Thursday, 31 May 2018

Question about reversal of `error` and `result` in node-mysql and Promise API.

I have an insert query promise that looks like this:const insert = (query, values) => new Promise((resolve, reject) => connect(config) .then(connection => connection.query(query, values, (error, result) => { if (error) { reject(error); } else { resolve(result); } })) ); But in order to call it, I do this:app.post('/users', (request, response) => { connection.insert('INSERT INTO users SET ?', request.body).then( (result, error) => { if (error) { console.log(error); } response.send(`User added to database: ${result.insertId}`); } ); }); Notice (error, result) => vs (result, error) =>.Does anyone know why this would be?Full code for reference.Thanks!

Submitted May 31, 2018 at 03:52PM by floppydiskette

No comments:

Post a Comment