Json return error {"isFulfilled":false,"isRejected":false} + Node

Asked

Viewed 1,208 times

1

I have the following code in the Node :

 var express = require('express');
    var app = express();
    
    app.get('/api/events', function(req, res, next) {
        var events = repositorio.ListAll();
        res.json(events); 
    })
      
    app.get('*', function(req, res) {
        res.sendfile('./public/index.html');
    });
     
    app.listen(9000);

But I perform the same query returns me on screen :

{"isFulfilled":false,"isRejected":false}

My repositorio.Listall() method is as follows :

  ListAll : function (){
    return event.findAll().then(function(eventCTX) {
      eventCTX
    });
  },

  • 1

    I think this one events It’s a trial, and you should have events.then(ev => res.json(ev));

  • The error continued, I don’t know if it is giving this error due to the fact that my query is in another layer. I believe there would be no problem but...

  • Removes the then(function(eventCTX) { inside ListAll

  • 1

    It worked, thank you

1 answer

0

Looking at your code I see that event.findAll() generates a Promise. So it would be enough to have return event.findAll() without the .then() and then use like this:

app.get('/api/events', function(req, res, next) {
    repositorio.ListAll().then(ev => res.json(ev))
})

Browser other questions tagged

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