Node.js is a versatile runtime environment that encompasses everything necessary for executing JavaScript programs. It finds extensive use in running server-side scripts to render content before delivering it to web browsers. In tandem with Node.js, there’s NPM (Node Package Manager), an application and repository used for the development and sharing of JavaScript code. This guide aims to walk you through the process of installing and updating Node.js and NPM on a Windows system while also delving into essential Node.js commands.
Before we embark on the installation journey, ensure you have the following:
Step 1: Download Node.js Installer
Step 2: Install Node.js and NPM from the Browser
Step 3: Verify Installation
To ensure a successful installation, open a command prompt or PowerShell and enter the following commands:
node -v
This command will display the version of Node.js installed on your system. You can also verify the NPM version:
npm -v
The simplest way to update Node.js and NPM is to download the latest version of the software. On the Node.js download page, you’ll find the latest version listed right below the Windows Installer link. You can compare this version to the one you have installed.
To perform the update, download the installer for the latest version and run it. The setup wizard will automatically replace the old version with the new one.
If the need arises to uninstall Node.js and NPM, follow these steps:
Node.js functions as a framework and interprets the commands you provide. To test your Node.js installation, create a simple Hello World script:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('Hello World!');
}).listen(8080);
node \users\<your_username>\myprogram.js
Although it may appear as if nothing has happened, your script is running in the background. You might encounter a Windows Defender notice about allowing traffic; in this case, click “Allow.”
http://localhost:8080
You should see the text “Hello World!” in the upper-left corner. Your computer is now acting as a server, and any other device attempting to access your system on port 8080 will encounter the “Hello World” message.
To stop the program, switch back to PowerShell and press Ctrl+C. The system will revert to a command prompt, and you can close the window at your convenience.
You’ve successfully installed Node.js and the NPM package manager, and even created your first Node.js JavaScript program. The NPM framework provides access to a wide array of JavaScript solutions, which you can explore at npmjs.com. Enjoy your journey into the world of Node.js development!
© 2013 - 2024 Foreignerds. All Rights Reserved