Thursday, May 23, 2024

How to Install Node.js and NPM in Windows

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 latest Node.js version 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!

>>>Return to Angular Tutorial Page


Related Topics

  1. Introduction to Node.js
  2. Node.js REPL
  3. Angular Project Structure With File Description
  4. How to Setup Angular
  5. Angular First App - Hello world Example

You may also like-

  1. Angular Example to Render Multiple Rows
  2. How to Add Bootstrap to Angular Application
  3. Creating New Component in Angular
  4. Serialization in Java
  5. Object Cloning in Java
  6. Garbage Collection in Java
  7. Spring Web MVC Example With Annotations And XML Configuration
  8. Introduction to Hadoop Framework

No comments:

Post a Comment