Node.js : Day 5

Rahul Kumar
2 min readDec 17, 2024

15 days Challenge

WHAT IS EXPRESS, AND WHY USE IT?

👉 Express is a minimal node.js framework, a higher level of abstraction;

👉 Express contains a very robust set of features: complex routing, easier handling of requests and responses, middleware, server-side rendering, etc.

👉 Express allows for rapid development of node.js applications: we don’t have to re-invent the wheel;

👉 Express makes it easier to organize our application into the MVC architecture.

Setting Up Express

Step 1. Initialize a node project

Before you can use Express, you need to initialize a Node.js project. This involves creating a package.json file where all project dependencies and metadata are stored.

Run the following command in your terminal to initialize the project:

$ npm init

Step 2. Install express

$ npm i express

Step 3. Writing our First Express Server

const express = require("express");

// creating an express server
const app = express();

// define a simple route with get request
app.get("/", (req, res) => {
res.send("Hello From the server!!!");
});

// define a route with post request
app.get("/", (req, res) => {
res.send("This is post request!!!.");
});


// started server and server is listening on port 3000
app.listen(3000, () => {
console.log("App is running on port 3000");
});

Pros of Express

  1. Minimal and Flexible: Express is lightweight and doesn’t force you into a specific way of coding.
  2. Fast: Built for high performance and can handle many requests at once.
  3. Large Ecosystem: Many ready-to-use libraries (middleware) to add features easily.
  4. Routing: Easily define routes to handle different types of requests (GET, POST, etc.).
  5. Asynchronous: Can handle many operations at once without blocking other tasks.
  6. Scalable: Great for building large apps that can grow.
  7. Template Support: Works with template engines like EJS for dynamic web pages.
  8. Active Community: Lots of documentation and support from developers.

Cons of Express

  1. Minimal Structure: No predefined way to organize big apps, can lead to inconsistent code.
  2. No Built-In ORM: Doesn’t have a built-in tool for database interaction; you need a third-party tool.
  3. Middleware Complexity: Managing many middleware functions can get tricky in big apps.
  4. Callbacks: Uses callbacks, which can be hard to manage without promises or async/await.
  5. Limited Built-In Features: Doesn’t offer as many out-of-the-box features as other frameworks.
  6. No Official CLI: Unlike other frameworks, it doesn’t come with a built-in command-line tool to automate tasks.
  7. Not Ideal for Real-Time: Express doesn’t handle real-time features as well as other tools like Socket.io.

The framework is used by many leading companies such as Uber, Netflix, Airbnb, and IBM, making it a trusted choice for both small-scale applications and large enterprise systems.

Thanks…

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Rahul Kumar
Rahul Kumar

Written by Rahul Kumar

MERN Stack Developer building scalable web apps with MongoDB, Express.js, React.js, Node and TS. Sharing insights and best practices for modern web development.

No responses yet

Write a response