Quantcast
Channel: Tech Tutorials
Viewing all articles
Browse latest Browse all 938

How to Install Node.js and NPM in Windows

$
0
0

This article shows how you can download and install Node.js so that you can build network applications. Installation of Node.js is also a prerequisite for developing Angular applications.

We’ll also build a simple Node.js hello world application to verify the Node.js installation.


Downloading Node.js

You can download Node.js from this location- https://nodejs.org/en/download/

Node.js download

Installing Node.js

Double click on the downloaded Windows Installer (.msi) file to start the installation.

Nodejs installation

Double click on the downloaded Windows Installer (.msi) file to start the installation. Follow the instructions which includes-

  1. Accepting the license term
  2. Select the location where you want to install nodejs.
  3. Select the components to be installed.
  4. Check the box to automatically install tools for native modules.
  5. Click install button to start installation.

Checking for NPM

The Node Pack Manager (NPM) should also get installed as part of Node.js installation. To check if it is successfully installed, run the following command from command prompt.


npm -v

It should display version number for the NPM installation.

Checking Node.js installation

To verify Node.js installation you can run a simple Node.js HelloWorld application. Save the following code as helloworld.js.


const http = require('http');

const hostname = '127.0.0.1';
const port = 9000;

const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World');
});

server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});

Here http functionality is required so first thing is to specify it using require() function.

In the script http server is created which listens on port 9000. For any request received it sends ‘Hello World’ as response.

Navigate to the directory where helloworld.js is saved and run the following command.


F:\NETJS>Node helloworld.js

That starts the server which starts listening on port 9000. You can start a browser and type the following URL.

http://localhost:9000/

nodejs hello world

That's all for this topic How to Install Node.js and NPM in Windows. If you have any doubt or any suggestions to make please drop a comment. Thanks!


Related Topics

  1. How to Pass Command Line Arguments in Eclipse
  2. Creating a Maven Project in Eclipse
  3. Reflection in Java
  4. Spring Example Program Using Automatic Configuration
  5. Spring Web MVC Example With Annotations And XML Configuration

You may also like-

  1. Serialization in Java
  2. Object Cloning in Java
  3. Nested Class And Inner Class in Java
  4. Garbage Collection in Java
  5. String Vs StringBuffer Vs StringBuilder in Java
  6. Array in Java
  7. Lazy Initializing Spring Beans
  8. Introduction to Hadoop Framework

Viewing all articles
Browse latest Browse all 938

Trending Articles