I'm new to using async/await in nodejs and am confused about how to return data that I want for use in a view. Here is my code. below is the homeController, which is used like so:
app.get("/", homeController.index);
I tried making the index
method async, but i still can't console out the news data. what is the right way to resolve the article information so it's available for consumption in the view in home
?
async function getNewsData() {
const pool = await connection;
const result = await pool.request()
.input("StoryID", sql.Int, 154147)
.execute("News.uspStoryByIdGet");
console.log(result, "the result from the stored procedure");
return result;
}
const article = getNewsData().
catch((e) => {
console.log("the error", e);
});
export let index = async(req: Request, res: Response) => {
const article = await getNewsData();
console.log(article, "yoo");
res.render("home", {
article,
title: "Home",
});
};