Mr. Deepak Verma
Web Developer
Node.js Get Started

Learn Node JS by M-Learnify

Node JS

Node.js Get Started


Download and Install Node.js
  1. Go to https://nodejs.org
  2. Download the LTS (Long Term Support) version
  3. Run the installer and follow the instructions
Verify Installation

Open your terminal/command prompt and type:

node --version
npm --version

You should see version numbers for both Node.js and npm (Node Package Manager).

Troubleshooting

If the commands don't work:

  • Restart your terminal/command prompt
  • Make sure Node.js was added to your system's PATH during installation
  • On Windows, you might need to restart your computer
Getting Started: Create Your First Server

Once you have installed Node.js, let's create your first server that says "Hello World!" in a web browser.

Create a file called myfirst.js and add this code:


let http = require('http');

http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/html'});
  res.end('Hello World!');
}).listen(8080);
        

Save the file on your computer, for example:

C:\Users\Your Name\myfirst.js

This code creates a simple web server. When someone visits your computer on port 8080, it will show "Hello World!"

Command Line Interface

Node.js files must be initiated in your computer's Command Line Interface (CLI).

How to open the CLI depends on your OS:

  • Windows: Press the Start button and search for "Command Prompt" or type "cmd" in the search field
  • Navigate to the folder that contains myfirst.js. Your CLI should look something like:
C:\Users\Your Name>_
Initiate Your Node.js File

Start your CLI, type the following command, and hit Enter:

node myfirst.js

Now your computer works as a server! Anyone who accesses your computer on port 8080 will see "Hello World!"

Open your browser and type:

http://localhost:8080
โ† Back to Courses
Course Lessons