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:
Node.js Web Server
Next article icon

How to Run Node Server?

Last Updated : 10 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

A Node server runs JavaScript outside the browser to handle web requests. It listens for incoming requests, processes them, and sends responses. Unlike traditional servers, it handles multiple requests at once without waiting for each to finish.

Some of the key features of the Node Server are:

  • Non-Blocking, Asynchronous I/O
  • Single-Threaded Event Loop
  • Fast Execution due to V8 Engine
  • Cross-Platform
  • Built-in HTTP Module

Steps to Run a Node Server

Here’s a step-by-step guide to running your first Node server:

Step 1: Install NodeJS

If you haven’t installed NodeJS, follow the article- Install NodeJS in your System

To verify the installation, open your terminal or command prompt and type:

node -v

This will display the installed NodeJS version.

Step 2: Create Your Project Directory

Create a new directory for your project and navigate into it:

mkdir node-server
cd node-server

Step 3: Initialize the Project

Create a package.json file, which contains metadata about your project:

npm init -y

Step 4: Create a Basic Server

Create a file named server.js and add the following code to create a simple HTTP server

JavaScript
const http = require('http');   // Create the server const server = http.createServer((req, res) => {     res.writeHead(200, { 'Content-Type': 'text/plain' });     res.end('Hello World'); });  // Define the port and host const port = 3000; const host = 'localhost';  // Start the server server.listen(port, host, () => {     console.log(`Server running at http://${host}:${port}/`); }); 

Run the server by using the below command

node server.js

Output

Run NodeJS Server

In this example

  • http.createServer(): Creates an HTTP server that listens for requests.
  • res.writeHead(): Sends a response header with the status code 200 (OK).
  • res.end(): Ends the response and sends the message “Hello, World!” to the client.
  • server.listen(): Starts the server on the specified host (localhost) and port (3000).

Applications of Node Server

  • Real-Time Web Apps: Examples include chat apps, collaborative tools, and gaming.
  • APIs: NodeJS is widely used for building RESTful APIs.
  • Microservices: Can be used in microservice architecture for distributed systems.

Benefits of Using a Node Server

  • High Performance: Built on Chrome’s V8 engine, NodeJS provides fast execution, making it ideal for real-time applications.
  • Real-Time Capabilities: NodeJS provides in building real-time applications, such as chat apps or live data streaming, with its ability to handle multiple simultaneous connections.
  • Scalability: Its non-blocking, event-driven architecture allows NodeJS to handle thousands of concurrent requests efficiently, making it highly scalable.
  • JavaScript on Both Ends: Developers can use JavaScript for both client and server-side programming, simplifying the development process.


Next Article
Node.js Web Server

H

harshitpandey251
Improve
Article Tags :
  • Node.js
  • Web Technologies
  • Node.js-Basics
  • NodeJS-Questions

Similar Reads

  • How to Build a Node.js Proxy Server ?
    A proxy server acts as an intermediary between a client and other servers. It can be used for various purposes, including load balancing, security, and caching. In the context of web development, a proxy server forwards requests from clients to other servers, fetches responses, and sends them back t
    4 min read
  • Node.js Web Server
    A NodeJS web server is a server built using NodeJS to handle HTTP requests and responses. Unlike traditional web servers like Apache or Nginx, which are primarily designed to give static content, NodeJS web servers can handle both static and dynamic content while supporting real-time communication.
    6 min read
  • How To Start Next.js Server?
    Next.js is a React framework created by Vercel that helps developers build server-side rendered and static web applications. Starting a Next.js server is a simple process that allows you to see your application running in a local development environment or a production environment. PrerequisitesNode
    2 min read
  • How to Set Online SQL Server for Node.js ?
    An Online SQL server helps to connect your project with an online server instead of localhost database setup. To achieve this, the remotemysql site is popular for providing an online database to store our data in a secure way.  Installation of sql module: You can visit the link Install sql module. Y
    2 min read
  • How to Start MongoDB Local Server?
    MongoDB a NoSQL database, offers a local server environment that allows developers and users to work with MongoDB databases directly on their machines. This local server also known as a single-machine copy of MongoDB is an invaluable tool for various purposes, including development, testing, learnin
    4 min read
  • How to use Node.js REPL ?
    Node.Js REPL or Read-Evaluate-Print Loop is an interactive shell for the Node.js environment which means we can write any valid Javascript code in it. This is used to test, evaluate, experiment, or debug code much easier and accessible way. It basically acts as the Browser's Web dev tools' Console f
    6 min read
  • How to Fetch Images from Node Server ?
    The images, CSS files, JavaScript files, and other files that the client downloads from the server are known as static files. These static files can be fetched with the use of the express framework and without the use of it. The methods that can be used to serve static files are discussed below. The
    3 min read
  • How to Run a Node.js App as a Background Service ?
    Running a Node.js application as a background service is a common requirement for ensuring that your app stays running even after you log out, or if the system restarts. This can be particularly important for server-side applications, APIs, or any long-running processes. This article explores severa
    2 min read
  • How to Start and Stop MongoDB Server?
    MongoDB, a popular NoSQL database, is used by numerous users for its flexibility, scalability, and performance. It is very important to know how to start and stop a server before deep diving into mongoDB. In this article, we'll provide a comprehensive guide on how to initiate and terminate MongoDB s
    2 min read
  • How to connect mongodb Server with Node.js ?
    mongodb.connect() method is the method of the MongoDB module of the Node.js which is used to connect the database with our Node.js Application. This is an asynchronous method of the MongoDB module. Syntax: mongodb.connect(path,callbackfunction)Parameters: This method accept two parameters as mention
    2 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