I'm new to using Node.js and PostgreSQL.
I'm creating a post request with insert query.
How can I return inserted values to browser at the same time?
app.post('/car_create', (req, res) => {
const make = req.body.create_make;
const model = req.body.create_model;
client.query(`INSERT INTO cars (make, model) VALUES ($1, $2)`, [make, model], (error, results) => {
if (error) {
throw error
}
res.status(201).send(`Car added with ID: ${results};`);
console.log(res);
res.end();
});
});
How I can retrieve the data from response ?
Do I need to modify this line somehow?
res.status(201).send(`Car added with ID: ${results};`);