Install Nodejs on Windows

In this article we will get started using Node.js, a JavaScript runtime built on Chrome’s V8 JavaScript engine. We’ll also use the Node Package Manager (npm) to install a popular module called Express.

I’m using Windows 10 Pro x64 for these steps.

Install Node.js

  1. First step is to download the Windows installer from the official website

    I’ve got version v7.6.0 Current

  2. Run the installer and follow the prompts. You can accept all the defaults to get up and running quickly.

    Nodejs Install Wizard 01

    By default Node.js will be installed in C:\Program Files\nodejs, and the installer will automatically add node into your PATH variable for ease of use.

  3. When the installation has completed click Finish to close the wizard.

    Nodejs Install Wizard 02

    If you need to uninstall Node.js for any reason, it can be uninstalled from the Control Panel as usual.

  4. Launch a command prompt

  5. We can check the version using --version

    node --version

    Nodejs Version

  6. There is also a command-line interpreter

    console.log('hello world')

    Nodejs Hello World

    We can use JavaScipt like usual to execute operations, assign variables, etc. For example:

    5 * 2
    var x = 7
    x * 3

    Nodejs Interpreter

    Hit Ctrl + C to try exit. Node.js will give you a hint that you need to do it twice . Hit Ctrl + C again to exit.

    Alternatively, you can also use Ctrl + D to exit immediately.

  7. Lastly the documentation can be accessed using --help

    node --help

    Nodejs Interpreter

Node.js Hello World

This is a simple example which starts a local server and listens for connections.

  1. Create a new file helloserver.js

    var http = require('http');
    http.createServer(function (request, response) {
        // Send the HTTP OK Header
        response.writeHead(200, {'Content-Type': 'text/plain'});
        // Send the response body
        response.end('Hello World\n');
    console.log("Server running at http://localhost:8081");
  2. Launch a command prompt and run the example. This will start a local web server listening on port 8081.

    node helloserver.js

    Nodejs Hello World

  3. Launch a web browser and navigate to http://localhost:8081

    You should see a webpage with the text Hello World.

    When you’re done, hit Ctrl + C in the command prompt to kill the server.

Use npm to install Express

Express is a web framework for Node.js that comes with a ton of features to make life easier for developers. It’s useful for quickly throwing togethor APIs and services.

  1. First we need to make a directory to work from

    cd C:\dev
    mkdir nodejs
    cd nodejs
  2. The Express installation documentation is straightforward and I recommend following it. The minimum is shown here:

    npm install express

    This may take a minute or so to complete. When it’s finished you’ll have a new directory node_modules with a heap of stuff in it like \.bin, \accepts, and \array-flatten to name the first few.

Further Reading