How do I save a sequelize value to a variable in Node.js?

Asked

Viewed 108 times

1

I use the following code

var app = website.findOne({ where: { idwebsite: req.params.id } })
res.send(app);

But the result on the screen is that {"isFulfilled":false,"isRejected":false} How do I save the real value of select in the app variable?

1 answer

0

Hello,

For the error presented you must be receiving a file as return, there are two ways to connect with asynchronous situations in javascript

Using async/await

async getData() {
  return await website.findOne({ where: { idwebsite: req.params.id } })
} 
const app = await getData();
res.send(app);

unless mistake so would already work:

getData() {
  return website.findOne({ where: { idwebsite: req.params.id } })
} 
const app = await getData();
res.send(app);

or dealing with the Privileges by then/catch

let app;
website.findOne({ where: { idwebsite: req.params.id } }).
then( data => {
  app = data;
  res.send(app);
})

ps. these codes have not been tested

Browser other questions tagged

You are not signed in. Login or sign up in order to post.