I currently have a project which makes use of native Promises. I am looking to migrate these Promises over to Async/Await. I am having troubles migrating them over; I am trying to follow this article. Below is the current code with the Promises which need changing to Async/Await.
routes.js
// Importing user information
import user from '../server-controllers/user';
// User Information Route
router.get('/about', (req, res) => {
user.profile().then((data) => {
return res.render('user', {
title: data,
});
}).catch((e) => {
res.status(500, {
error: e,
});
});
});
user.js
/*
This file contains any server side modules needed.
*/
module.exports = {
// Returns information about a user
profile: () => {
return new Promise((resolve, reject) => {
const user = "John Doe";
resolve(user);
});
},
};
If there is any help in what I would need to do to convert these that would be helpful. I don't know if the code needs changing on either the routes or user file (or both).
The error which I am getting in my terminal is [object Error] { ... }
thencall byawait.