express javascript next node.js

check if there is a next() function express

is there a way to see if there is a function after the current middleware.

router.get('/', function(req, res, next){
if(next){//always returns true

I have a function to fetch the information and depending on the route that information will either be displayed in a table or a form or it will be combined with other data.

I wanted to have a function similar to

function findAll(req, res, next){
db.findAll(function(err, docs){
req.list = docs
return next();
res.render('table', {list:docs};

that way I could use the same function in either

router.get('/', findAll, handleData);


router.get('/', findAll);

and in either case a response will be sent. is there a way i can define the stack for the router like express does in the next() handler


var layer = stack[idx++];

this catches the next function if it exists but I cannot access this scope from my function. is there a way i can define the layers myself.

This seems like it could be very usefull in preventing redundant code