Glen Swift Glen Swift - 16 days ago 7
Node.js Question

restify's body parser is not working for some reason

I don't understand why this works:

instance.use(restify.bodyParser());


but this doesn't work:

instance.use((req, res, next) => {
restify.bodyParser();
next();
});

Answer

use expects an argument of the form function (req, res, next). Therefore, when the first example works correctly, restify.bodyParser() is a function of this form. Hence, you will need pass req, res, next in the second example.

instance.use((req, res, next) => {
  restify.bodyParser()(req, res, next);
});