38

I just installed node.js. I tried writing node -v that should check the version - and it's not working. this is the output:

 > node -v ReferenceError: node is not defined 

at repl:1:2 at REPLServer.self.eval (repl.js:110:21) 

at Interface.<anonymous> (repl.js:239:12) 

at Interface.emit (events.js:95:17) 

at Interface._onLine (readline.js:202:10) 

at Interface._line (readline.js:531:8) 

at Interface._ttyWrite (readline.js:760:14) 

at ReadStream.onkeypress (readline.js:99:10) 

at ReadStream.emit (events.js:98:17) 

at emitKey (readline.js:1095:12) >

I opened it using git - command: node

I tried running it using "Git", thought maybe that's the issue and I get the exact same output.

I am using windows 8 if it's relevant - followed this tutorial till now:

https://www.youtube.com/watch?v=tlntE8fe6u4

http://youtu.be/FqMIyTH9wSg

How do I make it work?

9
  • have you tried restarting the git bash? may be restart your system?
    – amyn
    Nov 27, 2014 at 11:49
  • I tried just now. nothing :( Nov 27, 2014 at 11:52
  • try adding the following in your path variable: C:\Program Files\nodejs\
    – amyn
    Nov 27, 2014 at 11:54
  • ^ I'm not sure what that means @amyn. I tried running it using CMD and I got the same output Nov 27, 2014 at 11:57
  • Right click on My Computer -> Properties -> Advanced System Settings on the left side -> Advanced Tab -> Environment Variables.. -> System Variables -> Double click on Path and append the following without quotes: ";C:\Program Files\nodejs\" I assume the above path is where nodejs is installed on your system
    – amyn
    Nov 27, 2014 at 12:00

7 Answers 7

68

It looks like you have entered the node REPL and then typed node -v

The good news is that this means node is working!

To check the version from here you can type process.version to get the node version. Alternatively type process.exit() to exit the node REPL and get back to bash (or equivalent terminal).

From here node -v should just output the node version.

3
  • Based benbrunton to the rescue. Jan 16, 2016 at 2:27
  • @benbrunton So, what is this process then? just a simple nodejs process? trying to run .js files? thanks :)
    – user4398985
    Jul 26, 2016 at 17:47
  • To answer your question, this is the nodejs REPL module. When node is installed it's functionality becomes associated with various commands (via above mentioned system variables 'path' association). Once installed, running node.exe from windows is not necessary to run js files. From cmd, bash, and I'd imagine git etc you can simply use the commands $ node myfile.js from the current directory. Jul 29, 2016 at 9:19
49

Edit

First time using node.js

Although already answered, but just putting in my 2-cents,

Normally, the first time users would trip over it, so am posting some screen shots, and that OP wants to try node -v, so making it a bit easier to follow.

The Wrong !!

Win+S> Node // or you open it by some other way

then you try here 'node -v' , which throws error


The Correct !!

Here it should work as expected


or you can do ..

then you have to go with another command

Hope it helps someone.!

4
  • When I type node -v I am getting "ReferenceError: node is not defined". but process.version option worked for me, thanks
    – Shamli
    Mar 12, 2017 at 22:47
  • @Shamli You check the Wrong and the Correct in the post.. you should get it working by node -v as well
    – Irf
    Mar 13, 2017 at 11:15
  • Thanks, I did not notice that
    – Shamli
    Jul 28, 2017 at 16:07
  • 1
    This answer is more clear to see the difference. Thank you @Irf .Adding another Info, when I searched for cmd, a specific 'Node.js command prompt' also showed. Entered into there and tried thr node -v. Worked.
    – Shivani
    Dec 9, 2022 at 18:33
16

Instead of node.exe, try to run node from "Node.js command prompt".

First, you should install nodejs.msi from nodejs.org.

Once installation is completed, go to: Start > All Programs > Node.js > Node.js command prompt.

It worked for me.

4
  • Where this "Node.js command prompt" comes from? Please post a link for documentation to understand you better
    – jperelli
    Mar 8, 2015 at 0:18
  • 3
    You should install nodejs.msi from nodejs.org and then after installation is completed go to: Start>All Programs>Node.js>Node.js command prompt. It worked for me Mar 8, 2015 at 21:14
  • In Node.Js v4.4.7 the start menu item that is written about in this comment is node.exe, which you can observe by right clicking/properties. Obviously this worked for someone but see my comment above about how you do not want to be in node.exe to use the original node command. Jul 29, 2016 at 9:17
  • After installing Node.js I was able to start a command prompt and type "Node" or "Node -v" to show the version, but when I tried to use npm (or rather "npm -v") to show the version, it gave the message: "Uncaught ReferenceError: npm is not defined". When I ran Node from the All Programs ("All apps" on windows 11) menu as you have described, it worked. Thank you. (Probably a path or variable issue resolved by using the specific "node.js command prompt")
    – Jonno
    Mar 10, 2022 at 14:38
4

Even I faced the same when I install the NODE server and Try to execute "node-v" command from directly clicking on start up menu's NODE ICON. Instead of doing that all you need to do is GO TO command prompt then go to C:/program files/node path and type "node -v" command it will definitely going to display you the version of NODE.

enter image description here

2

Try opening up a new terminal (Run -> CMD) and then executing:

node /your_file_name.js

And to see which version you have installed, just execute:

node -v
2

Follow below Steps:

  1. Open command prompt: RUN > CMD
  2. Navigate to folder where nodejs is installed: C:\users\name>cd path_of_nodejs
  3. Open nodejs: C:\path_of_nodejs>node
  4. Exit from node REPL mode: >process.exit()
  5. You are ready for your node commands: >node -v
0
0

Thanks for this help.

If you are using windows, like me, and want a desktop shortcut and you already have the nice node.js desktop icon, edit the shortcut properties like this:

  1. right click and select properties
  2. click change Icon, select the current icon and click OK (to lock it in)
  3. in the target box, change it all to simply say cmd or c:\windows\System32\cmd.exe if you are pedantic.

now you have a command prompt, with the node.js icon, that opens in the folder you expect, that responds correctly to the node -v command.

Not the answer you're looking for? Browse other questions tagged or ask your own question.