How to run a hello.js file in Node.js on windows? How to run a hello.js file in Node.js on windows? windows 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.

  1. Download the Windows executable here: http://nodejs.org/#download
  2. Copy the file to C:\
  3. Create C:\hello.js
  4. 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/');
  1. Save the file
  2. Start -> Run... -> cmd
  3. c:
  4. C:>node hello.js

    Server running at http://127.0.0.1:1337/

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


Install the MSI file:Go to the installed directory C:\Program Files\nodejs from command prompt n

C:\>cd C:\Program Files\nodejs enter..

node helloworld.js

output:

Hello World


You need to make sure that node is in your PATH. To set up your path, this out.

Make sure that the directory that has node.exe is in your PATH. Then you should be able to run node path_to_js_file.js.

For a good "Hello World" example, check out: http://howtonode.org/hello-node