• Core Java
  • SQL Tutorial
  • Servlet
  • jQuery
  • PHP
  • JSP
  • Spring
  • Struts
  • Java IO

  • <

    Express.js Middleware

    Middleware is commonly used to perform tasks like body parsing for URL-encoded or JSON requests, cookie parsing for basic cookie handling, or even building JavaScript modules on the fly.

    Middleware functions are functions that have access to the request object (req), the response object (res), and the next middleware function in the application‚??s request-response cycle. These functions are used to modify req and res objects for tasks like parsing request bodies, adding response headers, etc.

    Example



    index.js
    
    var express = require('express');
    var app = express();
    
    //Simple request time logger
    app.use(function(req, res, next){
       console.log("A new request received at " + Date.now());
       
       //This function call is very important. It tells that more processing is
       //required for the current request and is in the next middleware
       function/route handler.
       next();
    });
    
    app.listen(3000);
    
    
    
    
















    © copyright 2017-2021 Completedone pvt ltd.