Express.js is a minimal and flexible Node.js web framework used to build web applications and REST APIs. It simplifies server-side development with features like routing, middleware, and HTTP utilities.
- Built on Node.js for fast and scalable server-side development.
- Simplifies routing and middleware handling for web applications.
- Supports building REST APIs, real-time applications, and single-page applications.
- Provides a lightweight structure for flexible and efficient server-side development.
Learn how to install Node.js on Windows, Linux, and macOS, and also how to Setup Express in a Node project.
First Express.js Program
Here’s how you can start with a basic Express.js application:
// Import Express
const express = require('express');
const app = express();
// Define a route
app.get('/', (req, res) => {
res.send('Welcome to the Express.js Tutorial');
});
// Start the server
app.listen(3000, () => {
console.log('Server is running on http://localhost:3000');
});
It will start a server, and when you visit http://localhost:3000, it will display
Welcome to the Express.js Tutorial- Express is imported using require('express'), and an app instance is created with express().
- A route is defined using the app.get() method, which responds with a message when the root URL (/) is accessed.
- The app.listen() method starts the server and listens on port 3000 for incoming requests.
Express Basic
Start by understanding what Express is and how to build a simple application.
- Introduction
- Node vs Express
- Installation and First Application
- Structure my Application
- Separate App and Server
- Unique features of Express
Functions
Learn the built-in functions before creating APIs.
- Express express.json() Function
- express.Router() Function
- express.static() Function
- express.urlencoded() Function
- express.raw() Function
- express.text() Function
- express() function Complete Reference
HTTP Request and Response
Understand how Express handles incoming requests and outgoing responses.
Request Objects
Learn how to access client data.
- req.app Property
- req.baseUrl Property
- req.body Property
- req.cookies Property
- req.fresh Property
- req.accepts() Function
- req.acceptsCharsets() Function
- req.acceptsEncodings() Function
- req.acceptsLanguages() Function
- Request Complete Reference
Response Objects
Learn different ways to send responses.
- res.app Property
- res.headersSent Property
- res.locals Property
- res.append() Function
- res.attachment() Function
- res.cookie() Function
- res.clearCookie() Function
- res.download() Function
- res.end() Function
- Response Complete Reference
Application Objects
Configure the Express application.
- app.locals Property
- app.mountpath Property
- Mount Event
- app.enable() Function
- app.disable() Function
- app.enabled() Function
- app.disabled() Function
- app.all() Function
- app.delete() Function
- Application Complete Reference
Routing & REST APIs
Learn how routing works.
- Express HTTP methods
- Create routes using Express and Postman
- router.METHOD() Function
- router.route() Function
- router.use() Function
- router.all() Function
- router.param() function
- Router Complete Reference
Middleware
Middleware is one of the most important Express concepts.
- Middlewares in Express
- Use of next() function
- Create custom middleware
- express-session middleware
- Express Error Handling
Authentication and Authorization
- REST API using the Express to perform CRUD
- Implement JWT authentication in Express app
- 1-Minute Session Expiry in Express.js