How to run a hello.js file in Node.js on windows?

How to run a hello.js file in Node.js on windows?

Here are the exact steps I just took to run the “Hello World” example found at http://nodejs.org/. This is a quick and dirty example. For a permanent installation you’d want to store the executable in a more reasonable place than the root directory and update your PATH to include its location.

  • Download the Windows executable here: http://nodejs.org/#download

  • Copy the file to C:\

  • Create C:\hello.js

  • Paste in the following content:

` 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/’);


- Save the file

- Start -> Run... -> cmd

- c:

- 
C:>node hello.js

Server running at http://127.0.0.1:1337/


That's it. This was done on Windows XP.