Node.js on Windows part 1: simple introduction

For a couple of months I was intrigued by node.js, but i couldn’t find any simple guides to start with node on windows. It turns out it is actually very simple to start learning node.js on windows. To start you need 4 things.

  1. The windows node server, nodejs.exe download at http://nodejs.org
  2. A hello world node script ( example.js )
  3. A command promt, set at the same locations as the script en node server
  4. And of course a browser

Hello World script

Save the script below as example.js in the same directory as the downloaded node.exe file.

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/html'});
  res.end('<h1>Hello Nodejs</h1>');
}).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/');

Start your first node script

Now all you need to do are the following steps.

  1. Start node.exe
  2. execute the script with the command prompt: node example.js
  3. browse to the node server wich is running at: http://127.0.0.1:1337/

Your screen should be comparable to the screenshot below

a screenshot of the node.js setup

I hope this was as easy for you as it was for me. For now I hope to wire some more intersting blog posts about Node on Windows, for example Node on IIS, but in the next post I will explore node.js a bit deeper