Skip to content

Instantly share code, notes, and snippets.

@andersonmendesdev
Last active September 2, 2018 21:48
Show Gist options
  • Save andersonmendesdev/a3b9e231d71049ea1727341905ae25d5 to your computer and use it in GitHub Desktop.
Save andersonmendesdev/a3b9e231d71049ea1727341905ae25d5 to your computer and use it in GitHub Desktop.
Promise in nodejs
const selectDate = (connection, id) => {
return new Promise ((resolve, reject) => {
connection.query('select * from cliente where codcliente = '+id, (err, result) => {
if(err){
reject(err)
}else{
resolve(result)
}
})
})
}
const myfunction = async() => {
console.log('before')
const data = await selectDate(connection, id)
console.log('after date= '+data)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment