middleware example
Example 1: middleware uses
const methodOverride = require('method-override');
const { url } = require("inspector");
server.use(methodOverride('_method'));
server.use(express.static("./public"));
server.set("view engine", "ejs");
server.use(express.urlencoded({ extended: true }));
Example 2: middleware in node js
var express = require('express')
var app = express()
var myLogger = function (req, res, next) {
console.log('LOGGED')
next()
}
app.use(myLogger)
app.get('/', function (req, res) {
res.send('Hello World!')
})
app.listen(3000)
Example 3: middleware uses
server.use(express.static('./public'));
server.use(express.json());
server.use(express.urlencoded({extended: true}));
const methodOverride = require('method-override');
server.use(methodOverride('_method'));
server.set('view engine', 'ejs');