Skip to content

Instantly share code, notes, and snippets.

@mattmaribojoc
Created February 11, 2019 18:30
Show Gist options
  • Save mattmaribojoc/aa11f044a5a64c91e62764726ede4dbc to your computer and use it in GitHub Desktop.
Save mattmaribojoc/aa11f044a5a64c91e62764726ede4dbc to your computer and use it in GitHub Desktop.
app.post('/addTodo', (req, res) => {
const collection = client.db('test').collection('todos')
var todo = req.body.todo // parse the information from the request's body
collection.insertOne({title: todo}, function (err, results) {
if (err) {
console.log(err)
res.send('')
return
}
res.send(results.ops[0]) // returns the document we just inserted
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment