Reputation: 555
Based on Express docs, a middleware must run each time app is launched following this code:
var app = express();
app.use(function (req, res, next) {
console.log('Time:', Date.now());
next();
});
Well, trying to execute with the most simple possilbe example middleware never is excuted:
var express = require('express');
var middleware = require('./middleware');
var app = express();
app.use(function (req, res, next){
console.log('MIDDLEWARE');
next();
});
module.exports = app;
Middleware never runs.
Also tryed to make it working from a separated file, but never runs.
Thanks
Upvotes: 0
Views: 38
Reputation: 1593
Middleware are lunch when there are any request to the server.
Create a route and send a request to that, the middleware would be lunched.
Upvotes: 1
Reputation: 555
Ups, seems to be they're launched when recieves a request. So using Postman it worked.
Upvotes: 0