Tonight I was trying to install Node.js on Windows and couldn’t find any straightforward documentation. Reason is each new release of Node.js has multiple ways it can be setup. For instance, older versions required Cygwin and some people use a .exe file. None of these methods are optimal, so I’ve written a tutorial on how to install Node.js own Windows and test it in 6 steps with less than 10 minutes of your time.node
Edit (2014-03-03): The below information is for Node 0.6 (including the code test sample). If you want to install the latest version just follow these simple steps and you should be good to go.web
Go to the NodeJS home pagewindows
Click install to download the .msi installer packageapp
Run it and follow the instrucitons, you now have NPM (node package manager) and Node.js installedless
Reset your computer to get everything working in your command-line interface (CLI)ide
To install Node.js on Windows is quite easy. You’ll just need to grab an installer package from their website and run it. Well it isn’t quite that easy, but its close.ui
Go no Node.js‘s website and download the Windows .msi installer file. This is literally all you need setup everything.this
Run Node’s .msi file from anywhere on your computer. An installation window will appear. All you need to do is agree to and click okay on everything. If your Node.js install is corrupted, you can re-run this file and select repair to fix it.spa
This is the step that everyone forgets. Once you’ve installed the .msi file you need to reset your computer. Failure to do so will prevent you from using Node in your command prompt. Wondering why? You need to flush Windows since its adjusting registry files and who knows what else under your computer’s hood.code
Just because you’ve installed Node.js doesn’t mean it works. In the next three steps, we’ll quickly walk through creating a test file and running it.
1
2
3
4
5
6
|
var
http = require(
'http'
);
http.createServer(
function
(req, res) {
res.writeHead(200, {
'Content-Type'
:
'text/plain'
});
res.end(
'Hello World\n'
);
}).listen(8888,
"localhost"
);
console.log(
'Server running at http://localhost:8888/'
);
|
To make sure your Node.js install works on Windows, create a simple hello world script with the above code. Call it test.js and store it somewhere easy to access on your computer. A location such as f:\nodeworkspace\helloworld.js will make your life easier when accessing the file via Windows Command Prompt. If you use a different location you’ll have to adjust the following examples.
Run your Windows Command Prompt and relocate to helloworld.js’s folder. Here you’ll need to run node helloworld.js. Running this line of code causes Windows to activate the file and output a message.
You probably noticed that running node test.js output a message identical/similar to Server running at http://localhost:8888/. To verify node is working correctly leave your command prompt running in the background, then copy and paste http://localhost:8888/ into your browser. This should display an image similar to the above picture. If it still isn’t working walk back through the above steps or leave a comment below for more help.
If you made it through the above steps there is nothing left to install Node.js on Windows. Your computer should run it fine and no further configuration is necessary.