Tuesday, 17 December 2024

Middleware in Node.js

In Node.js, middleware is a function that acts as an intermediary between software layers to process incoming requests and outgoing responses.

const express = require('express');
const app = express();

const middleFunc = (req, res, next) => {
    req.customText = "Test middleware function...";
    next();
}

app.use(middleFunc);

app.get('/', (req, res) => {
    res.send("Test node app with : "+ req.customText);
});

app.listen(5100);

No comments:

Post a Comment