Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • NodeJS Tutorial
  • NodeJS Exercises
  • NodeJS Assert
  • NodeJS Buffer
  • NodeJS Console
  • NodeJS Crypto
  • NodeJS DNS
  • NodeJS File System
  • NodeJS Globals
  • NodeJS HTTP
  • NodeJS HTTP2
  • NodeJS OS
  • NodeJS Path
  • NodeJS Process
  • NodeJS Query String
  • NodeJS Stream
  • NodeJS String Decoder
  • NodeJS Timers
  • NodeJS URL
  • NodeJS Interview Questions
  • NodeJS Questions
  • Web Technology
Open In App
Next Article:
How to Become a Backend Developer in 2025
Next article icon

Node.js Basics: Back-End Development in MERN Stack

Last Updated : 23 Apr, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Node.js is an open-source and cross-platform JavaScript runtime environment. It’s a powerful tool suitable for a wide range of projects. Node.js stands out as a game-changer. Imagine using the power of JavaScript not only in your browser but also on the server side.

Table of Content

  • What is MERN stack?
  • What is Node?
  • Why Node?
  • Key features of Node
  • Node Advantages
  • How NodeJS works?
  • Creating a Simple Node Application
  • Conclusion

What is MERN stack?

The MERN Stack is a JavaScript Stack that makes the deployment of full-stack web applications easier and faster. It includes four technologies: MongoDB, Express, React, and Node.js. MERN Stack is designed to simplify the development process and make it smoother.

  • MongoDB: Non-Relational Database
  • Express: Node.js web server
  • React: JavaScript Frontend Framework
  • Node: JavaScript Web Server

What is Node?

Node.js is an open-source, cross-platform JavaScript runtime built on Chrome’s V8 JavaScript engine. It allows the creation of scalable Web servers without threading and networking tools using JavaScript and a collection of “modules” that handle various core functionalities. It can make console-based and web-based node.js applications.

Why Node?

Node.js is used to build back-end services like APIs like Web App, Mobile App or Web Server. A Web Server will open a file on the server and return the content to the client. It’s used in production by large companies such as Paypal, Uber, Netflix, Walmart, and so on.Here are some reasons to choose Node.js :-

  • Easy to Get Started: Node.js is beginner-friendly and ideal for prototyping and agile development.
  • Scalability: It scales both horizontally and vertically.
  • Real-Time Web Apps: Node.js excels in real-time synchronization.
  • Fast Suite: It handles operations quickly (e.g., database access, network connections).
  • Unified Language: JavaScript everywhere—frontend and backend.
  • Rich Ecosystem: Node.js boasts a large open-source library and supports asynchronous, non-blocking programming.

Key features of Node

  • Non-blocking I/O: Node.js is asynchronous, enabling efficient handling of concurrent requests.
  • Event-driven architecture: Developers can create event-driven applications using callbacks and event emitters.
  • Extensive module ecosystem: npm (Node Package Manager) provides access to thousands of reusable packages.
Nodejs features

Node Advantages

  • Easy Scalability: Node JS is built upon Chrome V8’s engine powered by Google. It allows Node to provide a server-side runtime environment that compiles and executes JavaScript at lightning speeds.
  • Real-time web apps: Today the web has become much more about interaction. Users want to interact with each other in real-time. Chat, gaming, constant social media updates, collaboration tools, eCommerce websites, real-time tracking apps, marketplace, each of these features requires real-time communication between users, clients, and servers across the web.
  • Fast Suite: As we have discussed that Node is highly scalable and lightweight that’s why it’s a heavy favorite for microservice architectures. In a nutshell, microservice architectures mean breaking down the application into isolated and independent services.
  • Easy to learn and code: No matter what language you are using for the backend application you’re gonna need JavaScript for front-end anyway so instead of spending your time learning a server-side language such as Php, Java or Ruby on Rails, you can spend all your efforts in learning JS and mastering in it.
  • Data Streaming: Node comes to the rescue since it’s good at handling such an I/O process which allows users to transcode media files simultaneously while they are being uploaded. It takes less time compared to other data processing methods for processing data.
  • Non Blocking Event-Drive Archtecture: Unlikly other traditional web servers that wait for one request to finish before handling another, Node.js uses an event-driven architecture and this things makes effective for handling many concurrent requests.
  • Corporate Support: It’s an independent community aimed at facilitating the development of Node core tools. The foundation of Node was formed to speed up the development of Node, and it was intended to allow broad adoption of it.

How NodeJS works?

Node accepts the request from the clients and sends the response, while working with the request node.js handles them with a single thread. To operate I/O operations or requests node.js use the concept of threads. Thread is a sequence of instructions that the server needs to perform. It runs parallel on the server to provide the information to multiple clients. Node.js is an event loop single-threaded language. It can handle concurrent requests with a single thread without blocking it for one request.

How node.js works

Application of NodeJS

  • Web Development: Node.js powers server-side logic for web applications, handling HTTP requests and data processing efficiently.
  • Real-time Applications: It's ideal for building chat apps, online gaming platforms, and live streaming services due to its event-driven architecture and WebSocket support.
  • API Development: Node.js simplifies creating RESTful APIs and microservices, making it easy to handle requests, data validation, and response generation.
  • Single-page Applications: Used as the back-end for SPAs built with front-end frameworks like React and Angular, managing server-side logic and API integrations.
  • IoT (Internet of Things): Node.js is lightweight and suitable for managing IoT devices, handling sensor data, and facilitating communication between devices and cloud services.
  • Streaming Services: It's efficient for building video/audio streaming platforms, real-time analytics dashboards, and live broadcasting services due to its non-blocking I/O capabilities.

NodeJS Ecosystem

Node.js has a vibrant ecosystem with a plethora of libraries, frameworks, and tools. Here are some key components:

  • npm (Node Package Manager): npm is the default package manager for Node.js. It allows developers to install, manage, and share reusable code packages (called modules). You can find thousands of open-source packages on the npm registry.
  • Express.js: Express is a popular web application framework for Node.js. It simplifies routing, middleware handling, and request/response management. Many developers choose Express for building APIs, web servers, and single-page applications.
  • Socket.io: For real-time communication, Socket.io is a go-to library. It enables bidirectional communication between the server and clients using WebSockets or fallback mechanisms.
  • Mongoose: If you’re working with MongoDB (a NoSQL database), Mongoose provides an elegant way to model your data and interact with the database. It offers schema validation, middleware, and query building.

Creating a Simple Node Application

Step 1: Create a folder for the project using the following command.

mkdir node-basics
cd node-basics

Step 2: Initialize the Node application using the following command.

npm init -y

Step 3: Create a file server.js to create a simple hello program.

touch server.js

Project Structure:

eretg
Folder Structure

Example: Illustration to showcase the basic structure for Node.js

JavaScript
//server.js  const http = require('http');  const server = http.createServer((req, res) => {     res.writeHead(200, { 'Content-Type': 'text/plain' });      res.write('Hello, World!');      res.end(); });  server.listen(3000, () => {     console.log('Server is running on port 3000'); }); 

Step 4: To start the server run the following command.

node server.js

Output:

First Node app - output

Creating a Simple API

Use Express.js to create API endpoints that handle HTTP requests and responses.

JavaScript
//index.js  const express = require('express'); const app = express();  app.get('/api/hello', (req, res) => {     res.send('Hello from Node.js!'); });  const PORT = process.env.PORT || 5000; app.listen(PORT, () => {     console.log(`Server running on port ${PORT}`); }); 

Output:

Api in Nodejs example - output

Connecting to MongoDB

Use Mongoose to connect your Node.js application to MongoDB and define data models.

JavaScript
const mongoose = require('mongoose');  async function connectToDatabase() {     try {         // Connect to MongoDB using the provided connection string         await mongoose.connect('mongodb://127.0.0.1:27017/myapp', {             useNewUrlParser: true,             useUnifiedTopology: true         });         console.log("Database Connected");     } catch (error) {         console.error("Error connecting to database:", error);     } }  connectToDatabase();  // Define the user schema and model  // after establishing the connection const Schema = mongoose.Schema; const userSchema = new Schema({     name: String,     email: String,     age: Number });  // Create a User model based on the userSchema const User = mongoose.model('User', userSchema);  // Export the User model to use it elsewhere if needed module.exports = User; 

Output:

Node Database Connection

Conclusion

Node.js is a powerful platform for building scalable and real-time applications, especially in the context of the MERN stack. By understanding Node.js basics, its event-driven architecture, and integration with other technologies like Express.js and MongoDB, developers can leverage its capabilities to create robust back-end systems for modern web applications. Start exploring Node.js today and unlock the full potential of the MERN stack for your projects.


Next Article
How to Become a Backend Developer in 2025

S

swati4934
Improve
Article Tags :
  • Web Technologies
  • Node.js
  • MERN Stack

Similar Reads

    Web Development

    • How to become Web Developer [2025]
      How can I start learning web development? Is it easy? And how can I keep up with the latest web designing technologies? These are the questions that appear in every beginner's mind. There is also confusion between web designing and web development, but we’ll talk about web development. It depends on
      8 min read

    • Begin Web Development with a Head Start
      To get a head start in web development, you can take the following steps: Learn the basics: Learn the basics of HTML, CSS, and JavaScript, which are the building blocks of web development. You can use online tutorials and resources, such as Codecademy, W3Schools, and FreeCodeCamp to start learning.
      8 min read

    • 10 Best Web Development Project Ideas For Beginners in 2024
      Learning web development is an exciting journey that opens doors to lots of creative possibilities. But for beginners, figuring out where to start with projects can be tricky. This article provides you with the Top 10 web development project ideas that are perfect for sharpening your skills in 2024.
      8 min read

    • 30+ Web Development Projects with Source Code [2025]
      This article on Web Development Projects provides a list of project ideas with source code to help you practice and improve your web development skills. Whether you’re a beginner learning the basics or a developer looking to expand your knowledge, these projects are a great way to get hands-on exper
      5 min read

    • 100 Days of Web Development - A Complete Guide For Beginners
      How to become Web Developer?  What is the salary of a Web Developer? What are the skills required to become a web developer?  How many days will it take to become a web developer? To answer all these questions and give you a correct pathway, we have come up with 100 Days of Web Development that will
      7 min read

    Front-End Development

    • Frontend Development
      Front-end Development is the development or creation of a user interface using some markup languages and other tools. It is the development of the user side where only user interaction will be counted. It consists of the interface where buttons, texts, alignments, etc are involved and used by the us
      8 min read

    • What is Frontend Development? Skills, Salary and Roles
      Want to build those beautiful UIs that you scroll through to search for something? Want to become a front-end developer? You have landed at the right place. In this article, we'll be talking about everything that you should know in order to build your front-end development journey. We'll be covering
      6 min read

    • What is a Frontend Developer ?
      A Front-End Developer is type of a Software Engineer who handles the User Interface of a website. As we know web development can be divided into three categories Front-End Development, Back-End Development, and Full-Stack Development. The persons who know Front-End Development are known as Front-End
      3 min read

    • Frontend Developer Roadmap 2025
      Frontend development means to design the face of a website or application. It involves working on the appearance of the website. Building interactive buttons, using images and animations, or any other aspect that involves enhancing the appearance of the webpage. A web developer is one of the most de
      8 min read

    • How to Become a Front-End Developer? [2024]
      Pretty much sure that whenever you browse a website, the first thing that makes you decide whether you're going further with the particular website or not is the look and feel of it. Undoubtedly, no one prefers a website or application to have an inferior user interface or design.  The man who ensur
      8 min read

    • What Skills Should a Front-End Developer Have?
      Are you keen on becoming a front-end developer? How interesting! Front-end developers are like magic creators who create websites that show up extraordinary and work well. But what must you have to end up one? Let us explore the significant abilities each front-end engineer should have. What is Fron
      13 min read

    • How Much JavaScript is Required to Become Front End Developer?
      Front-end Development is the part of web development that is focused on the user end of a website or web application. It involves the development of elements that provides the interaction between the user and browsers. HTML, CSS, and JavaScript are the main components used by front-end developers. H
      8 min read

    • 10 Best Front-End Development Courses [2025]
      Do you want to become a front-end developer? If yes, are you looking for a path/guide which will help you to become one? You've come to the right place. Let's understand what is front-end development first. Frontend development is the most required and high-paying skill, companies are searching for.
      11 min read

    • Best Books to Learn Front-End Web Development
      There is a huge demand for Front-End Web Developers or Web Designers in IT, and Front-End Developer Jobs are also some of the highest-paying jobs. These all are the reason people love to choose this field. Frontend development is all about UI/UX, where the main concern is related to the layout, styl
      9 min read

    • 10 Best Tools For Front-End Web Development
      As you can see, online businesses are becoming more and more concerned about the UI of their respective websites to provide a better user experience and generate better ROI - the demand for Front-End Developers has also increased significantly in recent years. Reports say that an enriching, creative
      9 min read

    • How Much DSA is Required For Front End Developer Interview?
      Front-end developer creates the user-facing component such as the user interface(UI) and user experience(UX), that determines how the user interacts with the digital product. Front-end engineer works with generally HTML, CSS, JavaScript, and frameworks like React or Angular. But having a solid found
      10 min read

    • Frontend Developer Interview Questions and Answers - 2025
      Frontend development is an important part of web applications, and it is used to build dynamic and user-friendly web applications with an interactive user interface (UI). Many companies are hiring skilled Frontend developers with expertise in HTML, CSS, JavaScript, and modern frameworks and librarie
      15+ min read

    Back-End Development

    • What is Backend Development? Skills, Salary and Roles
      Backend development is a blessing to all of us that we are able to get everything done by just sitting at home. Be it booking tickets, watching movies, or any sort of thing, backend development plays a major role in building an application. It is also one of the highly demanding professions in the I
      7 min read

    • Backend Development
      Backend Development involves the logic, database, and other operations that are built behind the scenes to run the web servers efficiently. Backend Development refers to the server-side development of the web application. It is the part of the application where the server and database reside and the
      12 min read

    • Top 10 Backend Technologies You Must Know
      To provide any responsive and effective software solution, frontend, and backend are the two most essential technologies that work together. A back-end framework is used to create server-side web architectures stably and efficiently. Backend technologies focus on improving the hidden aspects of the
      11 min read

    • How to Become a Backend Developer in 2025
      A Backend Developer is responsible for the server-side of web applications. Unlike frontend developers, who focus on the parts of a website users interact with, backend developers ensure that the systems and databases work seamlessly to support the front-end operations. Server-Side Development: Writ
      10 min read

    • 10 Skills to Become a Backend Developer in 2024
      A backend developer is responsible for writing backend codes and communicating when the user triggers any particular action. Today they have become the backbone of web development and they’re in high demand on a vast scale of companies. Whatever you do in your application, the back end is responsibl
      10 min read

    • 10 Best Back-End Programming Languages in 2024
      If you are planning to get started with web development, then you must be aware that web development is broadly classified into two parts i.e. frontend development and backend development. The primary difference between these two is that frontend development serves the client side in which the focus
      7 min read

    • Node.js Basics: Back-End Development in MERN Stack
      Node.js is an open-source and cross-platform JavaScript runtime environment. It’s a powerful tool suitable for a wide range of projects. Node.js stands out as a game-changer. Imagine using the power of JavaScript not only in your browser but also on the server side. Table of Content What is MERN sta
      7 min read

    • How to Become a Backend Developer in 2025
      A Backend Developer is responsible for the server-side of web applications. Unlike frontend developers, who focus on the parts of a website users interact with, backend developers ensure that the systems and databases work seamlessly to support the front-end operations. Server-Side Development: Writ
      10 min read

    • Backend Developer Interview Questions
      Backend development involves working on the server side of web applications, where the logic, database interactions, and server management take place. It focuses on handling data, processing requests from clients, and generating appropriate responses. In this Top Backend Development interview questi
      15+ min read

    Fronted Vs Backend Development

    • Frontend vs Backend Development
      In web development, the terms frontend and backend are essential for understanding how websites and web applications work. These two components make up the core of any modern web application, each serving a unique purpose. Frontend is what users see and interact with on a website, like the layout, b
      6 min read

    • FrontEnd vs BackEnd: Which One Should I Choose?
      Developing a website is a wonderful task that now every individual wishes to do. There are more than 1 billion websites running today and more than 200 million of them are active. Web Development has become one of the most demanding and highest-paying jobs in India or outside India. The integral par
      7 min read

    • How to Switch from Frontend to Backend Developer
      In this digital world, backend development is crucial to creating any application and solution. It involves creating the backend of the application which can handle the API calls, send data to the client, receive requests, and authenticate users. This article will help you understand about the backe
      8 min read

    • How to Switch from Backend Developer to Frontend Developer
      In this technological world, People want to become a web developer and some of the working developers want to change their careers to different domains. Some backend developer wants to join the frontend development and want to work in a company as a frontend developer. This article is about How you
      8 min read

    Full Stack Development

    • What is Full Stack Development ?
      Full Stack Development refers to the development of both front end (client side) and back end (server side) portions of web applications. If you want to learn in full structure form then you should enrol in our Full stack devloper course! You'll learn to create powerful web applications from scratch
      6 min read

    • Full Stack Developer Roadmap [2025 Updated]
      Web Developer/ Full Stack Web Developer - How do you feel when you tag yourself with such titles? A long journey takes place to be called by such names. In the beginning, you might feel bored or terrified, but, trust me, this is the most popular and interesting field one should work on. You can also
      15 min read

    • How to Become a Full Stack Web Developer in 2025
      How did you feel when you created your first login form on a web page after so many trials and tested templates (don't say that you made everything from scratch...)? ... How did you feel when you gave the layout to your first web application after multiple changes (Yes...you took the reference of so
      9 min read

    • Requirements to become a full stack developer
      A full stack developer is a person who is an expert in designing, building, maintaining, and updating both the front end and back end of a website or a web application. A full-stack developer is someone who can develop both client and server software. One should be well familiar with front-end, and
      8 min read

    • Full Stack Developer Salary in India (2024)
      Full Stack Developer Salary in India- The average Full Stack Developer salary in India ranges between 5 to 9 LPA. The number can go as high as 16 LPA for experienced professionals with the right skills. Full-stack developers are responsible for building a web application's front and back end. Full-s
      9 min read

    • Top 10 Full Stack Development Trends in 2025
      Full stack development is the practice of building software systems or web applications that comprise both front-end and back-end components. A full-stack developer is good at multiple layers of the software development cycle and can work on different terms in the application building including, UI,
      10 min read

    • 12 Best Full Stack Project Ideas in 2025
      Full stack developers handle everything from front-end to back-end, making them very valuable in tech. To learn full stack and show off your skills, building real projects is a must. In this article, you'll find 12 great full stack project ideas to boost your portfolio. But first, let’s understand w
      14 min read

    • Full Stack Developer Interview Questions and Answers - 2025
      Full Stack Development is a crucial aspect of modern web applications, involving both frontend and backend technologies to build dynamic, scalable, and high-performance applications. Skilled Full Stack Developers proficient in HTML, CSS, JavaScript, React, Node.js, Express, MongoDB, Spring Boot, Dja
      15+ min read

    Full Stack Development Stacks

    • MERN Stack
      The MERN stack is a widely adopted full-stack development framework that simplifies the creation of modern web applications. Using JavaScript for both the frontend and backend enables developers to efficiently build robust, scalable, and dynamic applications. What is MERN Stack?MERN Stack is a JavaS
      9 min read

    • MEAN Stack
      In the world of full-stack development, the MEAN stack has became one of the top choice for building dynamic and robust web applications. Web development refers to the creating, building, and maintaining of websites. It includes aspects such as web design, web publishing, web programming, and databa
      9 min read

geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences