Sunday, 19 March 2017

TypeError: next is not a function

I'm running a Node.js-server and trying to test this Rest API that I made with Express. It's linked up to MongoDB using Mongoose.

I'm testing the individual routes using Postman and I get an error when trying to send a PUT-request to this route:

// PUT /meetings/:id
// Route for editing a specific meeting
router.put("/:id", function(req, res, next) {
    req.meeting.update(req.date, function(err, result) {
      if(err) return next(err);
      res.json(result);
    });
});

The error retrieved is this:

events.js:141
      throw er; // Unhandled 'error' event
      ^

TypeError: next is not a function

I cannot figure out where exactly this is coming from. I'm using the router.params-method to specify how the :id-parameter should be handled like this:

router.param("id", function(req, res, id, next) {
  Meeting.findById(id, function(err, meeting) {
    if (err) return next(err);
    if (!meeting) {
      err = new Error("Meeting not found");
      err.status = 404;
      return next(err);
    }
    req.meeting = meeting;
    return next();
  });
});



via user4612744

No comments:

Post a Comment