Joss
Joss

Reputation: 555

middlewares not running in Express

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

Answers (2)

DJeanCar
DJeanCar

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

Joss
Joss

Reputation: 555

Ups, seems to be they're launched when recieves a request. So using Postman it worked.

Upvotes: 0

Related Questions