Reputation: 13721
I have the following POST route to insert data into my postgres database:
router.post('/add', function(req, res) {
console.log('add route hit at ' + currentDate);
console.log(req.body);
knex('users').insert(
{first_name: req.body.first_name},
{last_name: req.body.last_name}
)
});
For some reason, this does not insert data into my database, but does not return any errors either. Can someone help?
Thank you!!
Upvotes: 1
Views: 1072
Reputation: 681
You need to call then
on the knex chain
router.post('/add', function (req, res) {
return knex('users')
.insert(req.body)
.then(function () {
res.send('welcome') // or something
})
})
Upvotes: 2