Logo
PortfolioPricingContact
Getting Started with Node.js – JavaScript Backend Series

Getting Started with Node.js – JavaScript Backend Series

Akash_Halder
•July 4, 2025•

Getting Started with Node.js – JavaScript Backend Series

A complete beginner's guide to Node.js for backend development using JavaScript. Learn architecture, tools, and how to build fast, scalable servers.

#javascript#backend#node-js#rest-api#server

Node.js for JavaScript Backend Development – A Complete Beginner's Guide

JavaScript has historically been used for client-side scripting in browsers. But with the rise of Node.js, JavaScript can now power both frontend and backend development. This shift has significantly changed the web development landscape, enabling developers to build full-stack applications using a single language.

This article serves as the first installment in a complete backend tutorial series built on JavaScript. We’ll begin by understanding Node.js at its core, walk through its architecture, installation, and command-line tools like npm, npx, and nvm, and explain foundational concepts such as REST APIs and non-blocking I/O.


Module 1: Introduction to Node.js

What is Node.js and why was it created?

Node.js is an open-source, cross-platform runtime environment that executes JavaScript code outside the browser. It is built on Chrome’s V8 JavaScript engine, which compiles JavaScript into highly optimized machine code.

Traditionally, JavaScript could only run in browsers. Node.js brought JavaScript to the server, allowing developers to build backend systems using the same language they use in the frontend.

node_js_internals

To answer the question why node.js was created?
We need to understand the origin of Node.js, it’s important to examine the limitations of traditional web servers (e.g., Apache) and programming languages like PHP or Ruby.

In conventional architectures, servers often used multi-threaded blocking I/O, meaning each incoming request would occupy a thread. If the server received thousands of requests simultaneously, it would need an equal number of threads or a queueing mechanism, resulting in scalability problems.

Node.js was designed to solve this by using a single-threaded event loop with non-blocking I/O. This allows Node.js to handle thousands of concurrent connections efficiently, making it ideal for I/O-heavy applications like real-time chat systems or RESTful APIs.

So, In short: “Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine.”

Module 2: Installing Node.js

Step-1: Downloading Node.js

Visit the official Node.js download page:

https://nodejs.org

You’ll find two versions available:

  • LTS (Long-Term Support): Recommended for most users, especially in production environments.
  • Current: Contains the latest features, ideal for testing and development purposes.

Select your operating system (Windows/macOS/Linux) and download the installer.

Step-2: Verifying Installation

After installing Node.js, open your terminal or command prompt and run:

node -v
npm -v

This verifies that both node and npm were successfully installed.

You may now also install VS Code, which is widely used for Node.js development: https://code.visualstudio.com

node_installation


Module 3: Understanding Node.js Architecture

Node.js follows an event-driven, single-threaded architecture. Unlike traditional multi-threaded server models, Node.js uses a single thread to handle multiple client requests using an event loop.

node_architecture

Here’s what happens under the hood:

  1. When a request comes in, Node.js assigns it to a callback function.
  2. If the request requires I/O operations (like reading a file or querying a database), it delegates the task to the system kernel or libuv (an internal library).
  3. Meanwhile, Node.js continues processing other requests.
  4. When the I/O operation is complete, Node.js picks up the callback and executes it via the event loop.

This is called non-blocking I/O. It enables Node.js to serve thousands of concurrent connections with low memory overhead and minimal latency.

You can illustrate this concept using a flowchart or diagram showing the event loop, thread pool, and callback queue.


Module 4: Writing Your First Node.js Program

Let’s write a simple HTTP server in Node.js without using any external framework.

Create a file called index.js in your project folder and open it in VS Code:

 // Importing the http module which has the capacity to create a server using the v8 engine.
const { createServer } = require('node:http');
 
const hostname = '127.0.0.1' || 'localhost';
const port = 3000;
 
const server = createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello from Node.js!');
});
 
server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

Run this file using:

node index.js

Open your browser and go to http://localhost:3000. You should see the message "Hello from Node.js!".

basic_server

Tip: We can render not only plain text but html also. We can send JSON response also. Here is an example below how to do it.


serving_html

Note: Did you Noticed? I just stopped the Server. Why is that?
To reflect the changes we made in the same file we have to stop the server and run it again.
It's because the server don't know what code you changed. It is executing the code you wrote earlier. When you re-start the server then it knows that you made a change. This is a Drawback of Node.js
Try Serving the JSON response by yourself.


Module 5: Understanding npm, npx, and nvm & Role of JS in Backend

Node.js comes with several essential tools in its ecosystem.

1. What is npm?

npm stands for Node Package Manager. It is used to:

  • Install packages and libraries (e.g., Express, Axios)
  • Manage project dependencies via package.json
  • Run scripts

Example:

npm init -y         # initializes a new project  
npm install express # installs Express.js. If you want to learn it like this, comment 'Express'

2. What is npx?

npx is a tool that allows you to execute packages without installing them globally.

Example:

npx create-react-app my-app

This will run the package without saving it permanently to your global environment.

3. What is nvm?

nvm stands for Node Version Manager. It allows you to install and manage multiple versions of Node.js on the same machine. It's basically manages a docker conatiner, we just pull it form it.

Checkout nvm from the official GitHub repository: https://github.com/nvm-sh/nvm

4. The Role of JavaScript in Backend Development

Using Node.js, JavaScript can now handle:

  • Server-side routing
  • Handling HTTP requests and responses
  • Managing databases (MongoDB, PostgreSQL, etc.)
  • Authenticating users and managing sessions
  • Serving frontend applications

This convergence of frontend and backend into a single language makes full-stack development more efficient and consistent.

Node JS is JavasScript run-time remember that, basically it creates server for you. So it only work is to serve your files on hitting a particular route.

Module 6: What is a REST API?

A REST API (Representational State Transfer API) lets a client (like a frontend app) communicate with a server over HTTP. It is widely used for building backend services that send and receive data, usually in JSON format.

REST APIs follow certain key principles:

  • Stateless: Each request is independent.
  • Client-server: The frontend and backend are separate.
  • Uniform interface: A consistent structure using URLs and HTTP methods.

Common HTTP Methods

  • GET – fetch data
  • POST – create new data
  • PUT – replace existing data
  • PATCH – update part of the data
  • DELETE – remove data

Example: User API Endpoints

  • GET /users → list users
  • POST /users → add a user
  • GET /users/1 → get user with ID 1
  • PUT /users/1 → fully update user 1
  • PATCH /users/1 → partially update user 1
  • DELETE /users/1 → delete user 1

You’ll use these routes to perform full CRUD operations (Create, Read, Update, Delete) on your backend.

Let’s now see how to build this using pure Node.js.

  • Create a file named script.js. In this we are going to perform Create, Read, Update, Delete (CRUD) operation using a Array. Later you can use a Database NoSQL/SQL.

  • Yes you heard it right! Nodejs can also be used with RDMS, SQL database. Infact the article you are reading is also coming from a SQL Database.

    const http = require('http');
     
    let users = []; // Fake in-memory database
    let idCounter = 1;
     
    const server = http.createServer((req, res) => {
        const { method, url } = req;
        const parts = url.split('/');
        const isUserRoute = parts[1] === 'users';
        const userId = parseInt(parts[2]);
        let body = '';
     
        req.on('data', chunk => body += chunk);
        req.on('end', () => {
          const data = body ? JSON.parse(body) : {};
     
          // GET /users
          if (method === 'GET' && url === '/users') {
            res.writeHead(200, { 'Content-Type': 'application/json' });
            res.end(JSON.stringify(users));
          }
     
          // GET /users/:id
          else if (method === 'GET' && isUserRoute && userId) {
            const user = users.find(u => u.id === userId);
            if (user) {
              res.writeHead(200, { 'Content-Type': 'application/json' });
              res.end(JSON.stringify(user));
            } else {
              res.writeHead(404);
              res.end('User not found');
            }
          }
     
        // POST /users
        else if (method === 'POST' && url === '/users') {
          const newUser = { id: idCounter++, ...data };
          users.push(newUser);
          res.writeHead(201, { 'Content-Type': 'application/json' });
          res.end(JSON.stringify(newUser));
        }
     
        // PUT /users/:id
        else if (method === 'PUT' && isUserRoute && userId) {
          const index = users.findIndex(u => u.id === userId);
          if (index !== -1) {
            users[index] = { id: userId, ...data };
            res.writeHead(200, { 'Content-Type': 'application/json' });
            res.end(JSON.stringify(users[index]));
          } else {
            res.writeHead(404);
            res.end('User not found');
          }
        }
     
        // PATCH /users/:id
        else if (method === 'PATCH' && isUserRoute && userId) {
          const user = users.find(u => u.id === userId);
          if (user) {
            Object.assign(user, data);
            res.writeHead(200, { 'Content-Type': 'application/json' });
            res.end(JSON.stringify(user));
          } else {
            res.writeHead(404);
            res.end('User not found');
          }
        }
     
        // DELETE /users/:id
        else if (method === 'DELETE' && isUserRoute && userId) {
          const index = users.findIndex(u => u.id === userId);
          if (index !== -1) {
            users.splice(index, 1);
            res.writeHead(204);
            res.end();
          } else {
            res.writeHead(404);
            res.end('User not found');
          }
        }
     
        // Fallback
        else {
          res.writeHead(404);
          res.end('Route not found');
        }
      });
    });
     
    server.listen(3000, () => {
      console.log('Server running at http://localhost:3000');
    });
  • Run the file using the command:

      node script.js

How to Test

On Linux/macOS Terminal

curl http://localhost:3000/users
curl -X POST http://localhost:3000/users -H "Content-Type: application/json" -d '{"name": "Alice"}'
curl http://localhost:3000/users/1
curl -X PUT http://localhost:3000/users/1 -H "Content-Type: application/json" -d '{"name": "Updated"}'
curl -X PATCH http://localhost:3000/users/1 -H "Content-Type: application/json" -d '{"age": 25}'
curl -X DELETE http://localhost:3000/users/1

On Windows PowerShell

Invoke-RestMethod -Uri http://localhost:3000/users -Method GET
Invoke-RestMethod -Uri http://localhost:3000/users -Method POST -Body (@{name='Alice'} | ConvertTo-Json) -ContentType "application/json"
Invoke-RestMethod -Uri http://localhost:3000/users/1 -Method GET
Invoke-RestMethod -Uri http://localhost:3000/users/1 -Method PUT -Body (@{name='Updated'} | ConvertTo-Json) -ContentType "application/json"
Invoke-RestMethod -Uri http://localhost:3000/users/1 -Method PATCH -Body (@{age=25} | ConvertTo-Json) -ContentType "application/json"
Invoke-RestMethod -Uri http://localhost:3000/users/1 -Method DELETE

Summary

Node.js is a foundational technology for modern backend development with JavaScript. It allows developers to write scalable, performant server-side applications using the same language used on the client side.

In this Module, we covered:

  • What Node.js is and why it was created
  • Installing Node.js and using essential tools like npm and npx
  • Node’s architecture and non-blocking I/O model
  • Writing a basic HTTP server in Node
  • Understanding the role of REST APIs

This serves as your first step into backend development using JavaScript. From here, you can move on to learning about development tools like nodemon, using Express.js to build more powerful APIs, and structuring your projects for real-world applications.

If you liked this article and want to learn more about JS Backend. Like this article and Comment 'Want to Learn More' in this article comment section. Till then keep exploring and keep learning!

...
#javascript#backend#node-js#rest-api#server

Short on Time?? Want to read Offline??

We have got you covered, Download the PDF version of this Blog!

Comments

Loading comments...

Related Posts

Stay tuned for related posts!

Logo

A passionate developer dedicated to creating engaging digital experiences.

Quick Links

  • About Me
  • Services
  • Pricing
  • Blogs
  • Careers
  • Contact

Products

  • Code Compiler
  • Aksha Docs
  • Tutorials
  • StreamScripts
  • Notes & Handbooks

Legal

  • Privacy Policy
  • Terms & Conditions

Get In Touch

  • Kolkata, West Bengal, India

© 2026 Akash Halder. All rights reserved.

Designed and built with ❤️ using Next.js, Tailwind CSS

Node.js for JavaScript Backend Development – A Complete Beginner's Guide
Module 1: Introduction to Node.js
What is Node.js and why was it created?
Module 2: Installing Node.js
Step-1: Downloading Node.js
Step-2: Verifying Installation
Module 3: Understanding Node.js Architecture
Module 4: Writing Your First Node.js Program
Module 5: Understanding npm, npx, and nvm & Role of JS in Backend
1. What is npm?
2. What is npx?
3. What is nvm?
4. The Role of JavaScript in Backend Development
Module 6: What is a REST API?
Common HTTP Methods
Example: User API Endpoints
How to Test
On Linux/macOS Terminal
On Windows PowerShell
Summary
Node.js for JavaScript Backend Development – A Complete Beginner's Guide
Module 1: Introduction to Node.js
What is Node.js and why was it created?
Module 2: Installing Node.js
Step-1: Downloading Node.js
Step-2: Verifying Installation
Module 3: Understanding Node.js Architecture
Module 4: Writing Your First Node.js Program
Module 5: Understanding npm, npx, and nvm & Role of JS in Backend
1. What is npm?
2. What is npx?
3. What is nvm?
4. The Role of JavaScript in Backend Development
Module 6: What is a REST API?
Common HTTP Methods
Example: User API Endpoints
How to Test
On Linux/macOS Terminal
On Windows PowerShell
Summary

About the Author

Akash_Halder
Admin

Akash_Halder

Hi 👋🏻 I'm Akash Halder – Founder and CEO of this platform and also a Full Stack Web Developer & Data Scientist skilled in JavaScript, Python, and UI/UX design. I build impactful digital solutions and create content that blends tech with creativity. Currently I'm pursuing a B.Tech degree in Computer Science (AI & ML) at Brainware University.

Learn more about the author →

Node.js for JavaScript Backend Development – A Complete Beginner's Guide
Module 1: Introduction to Node.js
What is Node.js and why was it created?
Module 2: Installing Node.js
Step-1: Downloading Node.js
Step-2: Verifying Installation
Module 3: Understanding Node.js Architecture
Module 4: Writing Your First Node.js Program
Module 5: Understanding npm, npx, and nvm & Role of JS in Backend
1. What is npm?
2. What is npx?
3. What is nvm?
4. The Role of JavaScript in Backend Development
Module 6: What is a REST API?
Common HTTP Methods
Example: User API Endpoints
How to Test
On Linux/macOS Terminal
On Windows PowerShell
Summary
Node.js for JavaScript Backend Development – A Complete Beginner's Guide
Module 1: Introduction to Node.js
What is Node.js and why was it created?
Module 2: Installing Node.js
Step-1: Downloading Node.js
Step-2: Verifying Installation
Module 3: Understanding Node.js Architecture
Module 4: Writing Your First Node.js Program
Module 5: Understanding npm, npx, and nvm & Role of JS in Backend
1. What is npm?
2. What is npx?
3. What is nvm?
4. The Role of JavaScript in Backend Development
Module 6: What is a REST API?
Common HTTP Methods
Example: User API Endpoints
How to Test
On Linux/macOS Terminal
On Windows PowerShell
Summary