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/
Installing Node.js
Double click on the downloaded Windows Installer (.msi) file to start the installation.
Double click on the downloaded Windows Installer (.msi) file to start the installation. Follow the instructions which includes-
- Accepting the license term
- Select the location where you want to install nodejs.
- Select the components to be installed.
- Check the box to automatically install tools for native modules.
- 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/
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
You may also like-
No comments:
Post a Comment