Install Node.js on Windows
It's really easy to install Node js if you are using Xampp or Wamp etc.
Nodejs.org has created a Windows Installer (.msi) for Node Js.
If don't have Xampp installed on your localhost, Download & Install Xammp.
Steps: How to Install Node js on Localhost:
- Download Windows Installer (.msi) for Node Js from Node Js Official Website.
- Run the Installer (.msi installer that you have downloaded) and follow the prompts steps in the installer.
- Congrats!, now you have installed node.js successfully with NPM and Node Modules.
Important Notes:
- NPM – Node Package Manager – which lets you add Node Packages/Modules like Express Js, Mongoose, PM2, Nodemailer etc very quickly and easily.
- Keep your Apache and Node ports different.
- Run - node -v on cmd to test the version of Node Js.
- Run - npm -v on cmd to test the version of NPM (Node Package Manager).
For Example:
// Install Express Js >> npm install express --save
You may also like - Nodejs Interview Questions
Now, Create simple program using Node Js:
Create a test file (for example) C:\nodejs\test.js and 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');
Now, Open cmd (COMMAND PROMPT) and run following command:
>> cd C:\nodejs >> node test.jsOpen this address in your browser:
http://127.0.0.1:3000