javascript - next() is not a function error Node.js -


var express = require('express'); var app = express();  var middleware = {     requireauthentication: function(req, res, next){         console.log("private route hit");         next();     } };  app.use(middleware.requireauthentication());   app.get('/about',      function(req, res){     res.send('you clicked on about!');      }  );   var projectdir = __dirname + '/public';  app.use(express.static(projectdir)); app.listen(3000), function(){     console.log('static service started');  }; 

i error (when trying run server) next() not function. i've been following tutorial on nodejs , works fine them. issue having here?

this line:

app.use(middleware.requireauthentication()); 

calls method , passes return value app.use. you're not calling arguments, naturally next parameter undefined.

get rid of () you're passing function, not result, app.use:

app.use(middleware.requireauthentication); // no () here --------------------------^ 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -