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:
Express JS sendfile() vs render()
Next article icon

Node vs Express

Last Updated : 07 Jan, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Node.js and Express are two essential tools in the JavaScript ecosystem, especially for server-side development. While they are often used together, they serve different purposes. This article will explain what Node.js and Express are, their key differences, and when to use each.

Table of Content

  • Node JS
  • Express JS 
  • Below are basic examples of creating a server in Node JS & Express JS
  • Routing in Express JS
  • Routing in Node JS
  • Difference between Node JS and Express JS

Node JS

Node JS is an open-source and cross-platform runtime environment for executing JavaScript code outside of a browser. You need to remember that Node JS is not a framework and it’s not a programming language. Most people are confused and understand it’s a framework or a programming language. We often use Node.js for building back-end services like APIs for Web Apps or Mobile Apps. It’s used in production by large companies such as Paypal, Uber, Netflix, Walmart, and so on. 

Express JS 

Express is a small framework that sits on top of Node JS’s web server functionality to simplify its APIs and add helpful new features. It makes it easier to organize your application’s functionality with middleware and routing. It adds helpful utilities to Node JS’s HTTP objects. It facilitates the rendering of dynamic HTTP objects.

Note: These codes are covered in the below comparisons.

Example: The following comparison shows how the same code is written differently in Node.js (Left tab code) and Express.js (Right tab code). 

While Node.js provides the runtime, Express is a web framework that simplifies building server-side applications.

Below are basic examples of creating a server in Node JS & Express JS

Express JS Server:

Step to Install Express: Install Express using the following command.

npm i --save express
JavaScript
// Filename - index.js  // Requiring the module const express = require('express'); const app = express();  // Route handling app.get('/', (req, res) => {     res.send('<h2>Hello from Express.js server!!</h2>'); });  // Server setup app.listen(8080, () => {     console.log('server listening on port 8080'); }); 

Steps to Run the Server: Run the index.js file using the following command:

node index.js

Output:

Node JS Server:

Require the HTTP module using the following code:

const http = require('http');
JavaScript
// Filename - index.js  // Requiring the module const http = require('http');  // Creating server object const server = http.createServer(     (req, res) => {         res.setHeader('Content-Type', 'text/html');         res.write('<html>');         res.write( '<head><title>GeeksforGeeks</title><head>'         );         res.write( '<body><h2>Hello from Node.js server!!</h2></body>'         );         res.write('</html>');         res.end();     });  // Server setup server.listen(3000, () => {     console.log("Server listening on port 3000") }); 

Steps to Run the Server:

node index.js

Output:

Routing in Express JS

Routing in Express.js simplifies implementation, offering ease of use. Through Express’s built-in functions, we can directly specify route names and associated functions, indicating the type of request, whether it’s a GET or POST, for instance. This streamlined approach streamlines the development process, enhancing productivity and reducing complexity.

JavaScript
// Filename - index.js  // Requiring module const express = require('express'); const app = express();  // Handling '/' request app.get('/', (req, res) => {     res.send('<h2>Hello from Express.js server!!</h2>'); });  // Handling '/about' request app.get('/about', (req,res) => {     res.send('<h2>GeeksforGeeks- Express.js</h2>'); });  // Server setup app.listen(8080, () => {     console.log('server listening on port 8080'); }); 

Steps to Run the Server: Run the index.js file using the following command:

node index.js

Open your browser and go to http://localhost:8080/about, following will be the output:

Routing in Node JS

In Node.js, routing isn’t inherently provided. Instead, developers must manually inspect the URL and method of each incoming request to determine how to handle and respond to it appropriately. This means that routing logic needs to be implemented within the application code, typically through conditional statements or frameworks like Express.js, which offer more structured routing capabilities. By checking the URL and method of each request, developers can tailor responses dynamically based on the specific requirements of the application.

JavaScript
// Filename - index.js  // Requiring the module const http = require('http');  // Creating server object const server = http.createServer((req, res) => {     const url = req.url;          if(url === '/') {         res.write('<html>');         res.write( '<head><title>GeeksforGeeks</title><head>');         res.write( '<body><h2>Hello from Node.js server!!</h2></body>');         res.write('</html>');         return res.end();     }          if(url === '/about') {         res.write('<html>');         res.write( '<head><title>GeeksforGeeks</title><head>');         res.write( '<body><h2>GeeksforGeeks- Node.js</h2></body>');         res.write('</html>');         return res.end();     } });  // Server setup server.listen(3000, () => {     console.log("Server listening on port 3000") }); 

Steps to Run the Server:

node index.js

Output: Open your browser and go to http://localhost:3000/about:

Difference between Node JS and Express JS

  • Node JS is a platform for building I/O applications that are server-side event-driven and made using JavaScript.
  • Express JS is a framework based on Node JS which is used for building web applications using approaches and principles of Node JS’s event-driven architecture.
FeatureExpress JSNode JS
UsageIt is used to build web apps using approaches and principles of Node JS It is used to build server-side, input-output, event-driven apps.
Level of featuresMore features than Node JS.Fewer features.
Building BlockIt is built on Node JSIt is built on Google’s V8 engine.
Written inJavaScriptC, C++, JavaScript
Framework/PlatformFramework based on Node JSRun-time platform or environment designed for server-side execution of JavaScript.
ControllersControllers are provided.Controllers are not provided.
RoutingRouting is provided.Routing is not provided.
MiddlewareUses middleware for the arrangement of functions systematically server-side.Doesn’t use such a provision.
Coding timeIt requires less coding time.It requires more coding time.




Next Article
Express JS sendfile() vs render()

S

Shubhadarshie
Improve
Article Tags :
  • Difference Between
  • Express.js
  • JavaScript
  • Node.js
  • Technical Scripter
  • Web Technologies
  • Algorithms-Graph Traversals
  • C++-Misc C++
  • Java-HijrahDate
  • Java-SecureRandom
  • Node.js-Misc
  • Python numpy-Random
  • TCS-coding-questions
  • Technical Scripter 2020
  • Web Technologies - Difference Between

Similar Reads

  • How Express Works?
    ExpressJS is a fast and minimal web application framework that is built on top of NodeJS. It provides a robust set of features such as handling HTTP requests, implementing middleware, routing etc. which can be utilized to build dynamic web applications, mobile applications and implement APIs. It is
    4 min read
  • Express.js vs KoaJS in Node.js
    Node.js: Node.js is an open-source and cross-platform runtime environment for executing JavaScript code outside a browser. You need to remember that NodeJS is not a framework and it’s not a programming language. Most of the people are confused and understand it’s a framework or a programming languag
    4 min read
  • Express res.render() Function
    ​The res.render() function in Express.js is used to render a view template and send the resulting HTML to the client. This allows you to dynamically generate HTML pages by combining your templates with data. Syntax: res.render(view [, locals] [, callback]);Parameters view (required): A string repres
    4 min read
  • Express res.send() Function
    The res.send function is used to send a response in form of various types of data, such as strings, objects, arrays, or buffers, and automatically sets the appropriate Content-Type header based on the data type. res.send in ExpressThe res.send() function sends the HTTP response. The body parameter c
    3 min read
  • Express JS sendfile() vs render()
    sendFile() function in Express.js is mainly used to send the file at the given path whereas the render() function is used to render a view and send the HTML string to the client as a response. In this article, we will see the detailed difference between this function with their syntax and practical
    3 min read
  • Introduction to Express
    Prerequisite - Node.js What is Express? Express is a small framework that sits on top of Node.js's web server functionality to simplify its APIs and add helpful new features.It makes it easier to organize your application's functionality with middle ware and routing; it adds helpful utilities to Nod
    2 min read
  • Express.js req.get() Function
    The req.get() function returns the specified HTTP request header field which is a case-insensitive match and the Referrer and Referrer fields are interchangeable. Syntax: req.get( field )Parameter: The field parameter specifies the HTTP request header field. Return Value: String. Installation of the
    2 min read
  • Express app.use() Function
    The app.use() function in Express.js adds middleware to the application's request-processing pipeline. It applies the specified middleware to all incoming requests or to specific routes, allowing you to modify request/response objects, perform operations, or handle errors throughout the application.
    3 min read
  • Express.js | app.get() Function
    The app.get() function returns the value name app setting. The app.set() function is used to assign the setting name to value. This function is used to get the values that are assigned. Syntax: app.get(name) Installation of the express module: You can visit the link to Install the express module. Yo
    1 min read
  • Express.js res.get() Function
    The res.get() function returns the HTTP response header specified by the field. The match is case-insensitive. Syntax: res.get( field ) Parameter: The field parameter describes the name of the field. Return Value: It returns an Object. Installation of the express module: You can visit the link to In
    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