You need to add the ‘return’ so that you don’t reply twice.
// save post and check for errors
post.save(function(err) {
if (err) {
return res.send();
}
res.json({ message: 'post created!' });
});
More Related Contents:
- static files with express.js
- How can I set cookie in node js using express framework?
- Difference between app.use and app.get in express.js
- IIS, Node.js, and Web Application with IISNode not configured right with Virtual Directory
- MongoDB/Mongoose querying at a specific date?
- express logging response body
- What is the parameter “next” used for in Express?
- Expressjs raw body
- When to use next() and return next() in Node.js
- How to populate a sub-document in mongoose after creating it?
- passport’s req.isAuthenticated always returning false, even when I hardcode done(null, true)
- mongoose custom validation using 2 fields
- req.query and req.param in ExpressJS
- Get hostname of current request in node.js Express
- Proxy with express.js
- Redirect all trailing slashes globally in express
- Docker – SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:3306
- Catch all uncaughtException for Node js app
- Nodejs HTTP and HTTPS over same port
- Passing an object to client in node/express + ejs?
- What is Express.js? [closed]
- Mongoose – caused by :: 11000 E11000 duplicate key error index?
- In express how do I redirect a user to an external url?
- Firebase Functions HTTPS 403 Forbidden
- Slack dialog doesn’t close after form submission
- Amazon EC2 NodeJS server stops itself after 2 days even after using sudo nohup
- What is the proper way to check for existence of variable in an EJS template (using ExpressJS)?
- Toggle between multiple .env files like .env.development with node.js
- body-parser – extended option (qs vs querystring)
- How to limit upload file size in express.js