
What is express JS?
- Express.js is a web application framework that is built on top of Node.js.
- Express is a lightweight and flexible routing framework
- Express is built on top of Node’s HTTP module, which enables it to be nimble in design and lightweight while yet preserving Node’s stability.

Features of Express
- Express quickens the development pace of a web application.
- Express follows the Model-View-Controller (MVC) architecture.
- It makes the integration process with databases such as MongoDB, Redis, MySQL effortless
- It also helps in creating mobile and web application of single-page, multi-page, and hybrid types
These were a few of the major advantages of using Express.js in web application development.
Body parser
Processes incoming request bodies, making it easier to handle POST and PUT requests. By parsing the body of an HTTP request and attaching it to the req.body property, it simplifies data extraction and manipulation in server-side logic.
When a client sends a request to the server, the body parser middleware intercepts this request. It parses different types of payloads, such as URL-encoded data or JSON, and then populates the req.body object with parsed data. This process turns the raw HTTP request body into a format that's more convenient to work with in JavaScript.
How Does it Work?
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
// parse application/json
app.use(bodyParser.json());
app.post('/submit-data', (req, res) => {
console.log(req.body); // Access the parsed body here
res.send('Data Received');
});
app.listen(3000, () => {
console.log('Server is running on port 3000');
});Routes and routing
Middleware

Controller

Controllers: Where we implement logic and send the response.
Express API Flow

Authentication
- Basic Authentication ( HTTP )
- Session based auth
- Token based Auth ( JWT )
- OAuth/OAuth2
- MFA

CORS
- Cross origin resource sharing
- https://medium.com/@emmaw4430/express-cors-middleware-simplifying-cross-origin-resource-sharing-d799f102c545

deck
By Syed Ali Haider Rizvi
deck
- 18