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