NodeJS Basics (original) (raw)

Last Updated : 25 Apr, 2026

Node.js is a JavaScript runtime environment built on Chrome’s V8 JavaScript engine that allows developers to execute JavaScript code outside the browser. It can make console-based and web-based Node.js applications.

**Some of the features of Node.js are mentioned below:

Setting Up Node.js

To start using Node.js, you’ll first need to install it on your system.

Step 1: Download and Install Node.js

Step 2: Verify Installation

Once installed, you can verify the installation by opening your terminal and typing the following commands:

node -v
npm -v

Step 3: Create a Node.js Project

Create a new directory for your project and initialize it with npm by running.

mkdir node-project
cd node-project

This will generate a package.json file, which is essential for managing your project dependencies.

npm init -y

Step 4: Write Your First Node.js Application

Create a new file called app.js and add the following code to create a simple HTTP server:

JavaScript `

const http = require('http');

const server = http.createServer((req, res) => { res.write('Hello World!'); res.end(); });

server.listen(3000, () => { console.log('Server running on port 3000'); });

`

**Output:

node app.js

Screenshot-2025-03-04-154548

NodeJs

Node.js Architecture

Node****.**js follows a single-threaded event loop model that handles all client requests using a single thread. It is based on a non-blocking I/O model, meaning the server can process multiple requests without waiting for one task to complete before starting the next.

Basic Node.js Concepts

1. Modules in Node.js

Node.js is based on modules, which are reusable pieces of code that can be imported into applications. These include built-in modules (like fs and http) and external packages installed using NPM.

**Common Node.js Modules

2. Event Loop and Asynchronous Programming

Node.js uses an event loop to handle asynchronous tasks without blocking execution, making applications fast and responsive.

Advantages of Using Node.js