Reputation: 7482
If I have the following Express router snippet how can I write a middleware to get the function name ?
var express = require('express'),
router = express.Router(),
....
router.get('/hello', helloWorld);
What I need to do is log the function name helloWorld. Given that my API is made up of 20+ such functions I just want to log these using bunyan or something similar to audit. Anyway to do this in Express ?
Upvotes: 0
Views: 733
Reputation: 301
Inside the helloWorld
function you can add a line as
var helloWorld = function(req, res, next){
var funName = helloWorld.name; // .name holds function name
}
or
function helloWorld(req, res, next){
var funName = helloWorld.name; // .name holds function name
}
For more info refer: function name
Please refer: middleware.router
Upvotes: 1