Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between node.js command promt and .exe

Tags:

node.js

I am sorry if this is a really generic question, however I've looked around and can't seem to find an answer.

I'm running node.js on Windows, and it has 2 things installed, Nodejs.exe and Node.js command prompt. I have gotten the script running with the command prompt, but I cannot figure out what the exe version does. The --debug flag which I want to use seems to only work on the exe. It seems it works similar to the python idle where you can type d = 6, then d and get the number 6 back, however I can't find anything else that it does.

Could somebody help explain what it is for? Thanks a ton!

like image 537
Spencer Fleming Avatar asked Nov 17 '13 14:11

Spencer Fleming


People also ask

What is nodejs command prompt?

It is a computer environment the same as command prompt and an easy way to test simple Node. js/JavaScript code and allows to execute multiple javascript codes. we can simply run REPL on the command prompt using node command on the command prompt.

Is npm an EXE?

If you find this question through google, Node. js for Windows comes with npm supplied (note: it's a script passthrough executable, not a true executable).

Which command is used to run node js?

Node. js can run shell commands by using the standard child_process module. If we use the exec() function, our command will run and its output will be available to us in a callback. If we use the spawn() module, its output will be available via event listeners.


2 Answers

There are two shortcuts provided when installing NodeJS on Windows:

Node applications installed on Windows

  1. Node.js = this is a captive shell for testing and executing JavaScript code. It's the same as if you typed node from a command prompt (assuming the node.exe is in the path). It's great for simple tests (and I often use it as a calculator).
  2. Node.js command prompt = this is a standard command prompt where the path has been adjusted to include node.exe (the NodeJS executable) along with npm, the Node Package Manager. In a default install though, the NodeJS directories are added to the system path, so node should be available from any command prompt.

So, using the command prompt (#2), you can use it to start scripts for example:

node app.js

Where app.js is the NodeJS code you've written.

As I mentioned though, node and npm are normally in the system path, so I don't use the two shortcuts. Instead, I just start a new command prompt:

  1. Win+R
  2. cmd Enter
  3. node Enter
like image 148
WiredPrairie Avatar answered Oct 15 '22 03:10

WiredPrairie


When you call the Node executable without any arguments, you are opening a REPL session.

A REPL - short for "Read, Evaluate, Print, Loop" - is used in different ways, depending upon the language/system it supports. Often, though, you'll find it most useful when you are:

  • Learning the system and want to test how fundamental concepts are implemented within the system. (Example: performing simple file system activities)
  • Testing an idea or exploring a problem with code, using an interactive environment so results can very quickly be viewed. (example: load a small bit of code your wrote and call it to view the output interactively as you tweak)

While a REPL can be useful when testing specific (and typically simple) matters, the REPL bogs down when things get more complex. As such, the REPL should be understood in the larger context of the Node ecosystem that includes tools like Forever and node-supervisor and a healthy suite of TDD options that can successfully be used to explore and test more complicated designs/problems.

like image 21
Matthew Bakaitis Avatar answered Oct 15 '22 04:10

Matthew Bakaitis