We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Haven't used any promises you can rewrite pretty much anything that uses a callback to use promises instead eg.
const actionQuery = cb => { dbConnection.query('SELECT * FROM actions', (err, res) => { if (err) return cb(err); cb(null, res.rows); }); };
could be rewritten to
const actionQuery = new Promise((resolve, reject) => { dbConnection.query('SELECT * FROM actions') .then(res => resolve(res.rows)) .catch(err => reject(err)) });
This can then be called using promises as well so instead of doing
getData.actionQuery((err, actions) => { if (err) return serverError(err, response); response.writeHead(200, {'Content-Type' : 'application/json'}); response.end(JSON.stringify(actions)) });
you could do
getData.actionQuery .then(actions => { response.writeHead(200, {'Content-Type' : 'application/json'}); response.end(JSON.stringify(actions)) }) .catch(err => serverError(err, response))
The text was updated successfully, but these errors were encountered:
Thanks!
Sorry, something went wrong.
No branches or pull requests
Haven't used any promises you can rewrite pretty much anything that uses a callback to use promises instead eg.
could be rewritten to
This can then be called using promises as well so instead of doing
you could do
The text was updated successfully, but these errors were encountered: