NodeJS Full Tutorials 2025

Node.js is a powerful tool that allows us to run JavaScript code in the browser, as well as on the server. Before Node.js, JavaScript was mostly used for creating dynamic web pages that were only client-side.

Now, we can write server-side code in JavaScript to handle client requests, manage databases, send responses, etc.

In simple terms, we can use only one language (JavaScript) for both the front end and the back end (server logic).

Node.js easily works on many systems like Windows, macOS, and Linux, and it’s designed for fast network applications such as chat apps, APIs, or streaming services.

Normally, JavaScript runs only in browsers like Chrome or Firefox, but Node.js uses Google Chrome’s V8 engines (the same way that runs JavaScript in Chrome), but it’s allows it to run anywhere, even on servers.

How To Setup Node.js In Our System?

First, we will install Node.js on your system with the following steps:

1) Download and Install Node.js

  1. Open the official Node.js website: https://nodejs.org.
  2. Download the LTS (Long-Term Support) version. It is more stable and recommended for beginners.
  3. Install Node.js by following the installer instructions.

2) Verify the Installation

After installation, open your terminal (Command Prompt on Windows or Terminal on macOS/Linux) and run the following commands to ensure Node.js is installed:

node -v

This command will display the installed Node.js version. Example output:

v18.12.1

Also, check the npm version:

npm -v

3) Write Your First Node.js Program

Let’s create a simple program to ensure everything is set up correctly.

Create a new file named app.js and add the following code:

console.log("Hello, Node.js!");

It will “Print the text Hello, Node.js! on the screen.”

Now, run this file in terminal using the following command:

node app.js

Output:

Hello, Node.js!

Real-World Example: Creating a Simple HTTP Server

This example is showing you how to make a very basic web server using Node.js.

const http = require('http');

// Create a server
const server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Welcome to Node.js!');
});

// Listen on port 3000
server.listen(3000, () => {
console.log('Server is running on http://localhost:3000');
});

Explanation of this code:

  • First, we import the HTTP module. Node.js comes with a built-in http module that allow us to create servers.
  • Then we create a server that can listen for requests.
  • (req, res) → req is the request from the browser, and res is the response you send back.
  • writeHead(200, {. . . }) → It will send a status code 200 (OK) and says the content is plain text.
  • res.end(‘Welcome to Node.js!’) → it will send the actual message and close the connection.

After writing the code, save the code file as server.js and then run with this command:

node server.js

Open your browser and visit: http://localhost:3000.

You will see the output:

Welcome to Node.js!

Common Important Questions

1. Is Node.js a Framework?
No, Node.js is not a framework. It’s a runtime environment that allows JavaScript to run outside the browser.

2. Can Node.js Handle Heavy Applications?
Yes, Node.js is designed for scalability. Its non-blocking architecture makes it suitable for handling heavy applications with large user bases.

3. How is Node.js Different from Traditional Servers?

Traditional servers like Apache, Java servers create a new thread (a separate worker) for each new user connection. For example: More users → more threads → more memory and CPU used.

This works better, but it can become heavy when there are thousands of connections.

Node.js uses only one main thread. That thread is event-driven, which means it listens for events (like “a user sent a request”) and responds when thread.

Common Mistakes Beginners Make

  1. Skipping LTS Version: Always use the LTS version unless you need the latest experimental features.
  2. Not Using npm: npm helps you manage dependencies, which makes your project easier to maintain.
  3. Blocking Code: Avoid writing synchronous (blocking) code, as it defeats the purpose of Node.js.