Skip to content

Instantly share code, notes, and snippets.

@meehanman
Created April 3, 2020 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meehanman/08a18ffe9333e82fee33bed3704ba56f to your computer and use it in GitHub Desktop.
Save meehanman/08a18ffe9333e82fee33bed3704ba56f to your computer and use it in GitHub Desktop.
NodeJS Examples of Promises for accessing AWS
return await docClient.query(findGameParams).promise().then((games) => {
if (games.Count == 1) {
return Promise.resolve(games.Items[0])
} else {
return Promise.reject("Could not find that game")
}
});
return await new Promise((resolve, reject) => {
docClient.query(findGameParams, function (err, games) {
if (err) {
return reject(err);
} else {
if (games.Count == 1) {
return resolve(games.Items[0]);
} else {
return Promise.reject("Could not find that game")
}
}
})
});
// ---------------------------------------
await gameController.gameInfo(req.params.gameid)
res.status(200).json(gameInfo);
// ...and surround in try{catch{
//---- or
gameController.gameInfo(req.params.gameid).then((data) => {
res.status(200).json(data);
}).catch((error) => {
res.status(400).json(error);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment