Replacing callbacks with promises in Node.js
I have a simple node module which connects to a database and has several functions to receive data, for example this function: dbConnection.js: import mysql from 'mysql'; const connection = mysql.createConnection({ host: 'localhost', user: 'user', password: 'password', database: 'db' }); export default { getUsers(callback) { connection.connect(() => { connection.query('SELECT * FROM Users', (err, result) => { if (!err){ callback(result); } }); }); } }; The module would be called this way from a different node module: app.js: import dbCon from './dbConnection.js'; dbCon.getUsers(console.log); I