Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node is not defined

Tags:

node.js

I just create a js file with the following code(exactly the code from official page):

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');

So, I install node from the 'Install' button in the official page too(for windows). But when I try to run the program it gives me the following:

enter image description here

but the strange thing is this:

enter image description here

like image 209
MuriloKunze Avatar asked Jan 07 '13 12:01

MuriloKunze


1 Answers

You need to run that from your terminal (cmd) as opposed to Node's repl.

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

node /your_file_name.js

To see which version you have installed, just execute:

node -v

like image 138
Marcos Placona Avatar answered Oct 20 '22 23:10

Marcos Placona