Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

First time using node.js - "ReferenceError: node is not defined"

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?

like image 212
Imnotapotato Avatar asked Nov 27 '14 11:11

Imnotapotato


People also ask

Is not defined NodeJS?

The "ReferenceError: path is not defined" occurs when we use the path module without importing it in a Node. js application. To solve the error, make sure to import the path module before using it - import path from 'path' . To solve the error, import the path module before using it.

What is reference error in NodeJS?

As discussed in the introduction, a ReferenceError is a common programming fault that occurs when code references an object that hasn't been previously defined or initialized. The most common cause of such an error is simple typos.


3 Answers

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.

like image 114
benbrunton Avatar answered Oct 17 '22 17:10

benbrunton


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.!

like image 47
Irf Avatar answered Oct 17 '22 16:10

Irf


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.

like image 14
Bernard Doci Avatar answered Oct 17 '22 16:10

Bernard Doci