You need to call nextafter adding method noticeto res.
app.use(function (req, res, next) {
res.notice = function (msg) {
res.send('[Notice] ' + msg);
}
next();
});
And you need to add this middleware before determining the routes.
UPDATE:
You need to add your middleware in front of the router.
var express = require('express');
var app = express();
app.use(function (req, res, next) {
res.notice = function (msg) {
res.send('[Notice] ' + msg);
};
next();
});
app.use(app.router);
app.get('/', function (req, res) {
res.notice('Test');
});
app.listen(3000);
source
share