How to Install NodeJS on Windows | Localhost
Step by Step Guide to Install NodeJS and NPM on Windows | Localhost.
Nodejs.org has created a Windows Installer (.msi) for NodeJS.
Steps by Step Guide to Install NodeJS on Windows | Localhost:
- Download Windows Installer (.msi) for NodeJS from NodeJS Official Website.
- Run the Installer (.msi installer) and follow the prompted steps in the installer.
- Congrats!, now you have installed NodeJS successfully with NPM and Node Modules.
How to check NodeJS and NPM Verison on Windows | Localhost:
Open either Windows CMD or Open Git Bash terminal, and type the following commands.
- node -v //it will show you installed version of NodeJS.
- npm -v //it will show you installed version of NPM (Node Package Manager).
Important Notes:
- NPM installed with NodeJS by default.
- Node Package Manager (NPM) – It lets you add Node Packages/Modules like ExpressJS, Nodemon, PM2, etc.
Example:
// Install express.js as dependency
>> npm install express --save
// Install nodemon as devDependency
>> npm install nodemon --save-dev
Create a NodeJS Server on your Windows | Localhost:
- Go to any of your directory in any drive on your local windows machine.
- Now, create a file (for example) C:\projects\test.js.
- Now, put the below code in that file.
var http = require("http"); http .createServer(function (req, res) { res.writeHead(200, { "Content-Type": "text/plain" }); res.end("Hello World\n"); }) .listen(3000, "127.0.0.1"); console.log("Server running at http://127.0.0.1:3000");
Note - You can change port from 3000 to any other if required
-
Now, Open cmd (Command Prompt) and run following command
>> cd C:\projects >> node test.js
- Go to the your browser and open this address in your browser:
http://127.0.0.1:3000
Note: I have given above example to just show you how to create a NodeJS server locally. but it always recommended to create your NodeJS Projects using npm init