0

I'm making a post request to a route i set up using express:

todolists.post('/getTodoLists', (req, res) => {
  TodoList.findOne({
    userEmail: req.body.userEmail
  })
    .then(todolist => {
      if (!todolist) {
        res.status(404).send()
      } else {
        res.status(200).json(todolist)
      }
    })
    .catch(err => {
      console.log(err)
      res.status(500).send(err)
    })
})

When i use the following code to retrieve data from the database, all i get in my console is 'object Object'

axios
  .post('todo-lists/getTodoLists', {
      userEmail: this.userEmail
   })
     .then(res => {
        console.log('response from gettodoLists' + res)
        this.todolist = res
        console.log(this.todolist)
      })
      .catch(err => {
        console.log(err)
      })

When i use Postman to make a request to the same route with the same request data i get all of the data that i expect to recieve.

Thanks in advance!

EDIT:

This is what i get from Postman

{
    "_id": "5caca1498accb128c8974d56",
    "title": "todolist1",
    "userEmail": "test@gmail.com",
    "todos": [
        {
            "_id": "5caca1498accb128c8974d57",
            "description": "Get this done",
            "completed": true
        }
    ],
    "dateDue": "2019-04-07T18:24:31.207Z",
    "__v": 0
}

This is what i get in my console when i console log the response

response from gettodoLists[object Object]
eikeka
  • 20
  • 6
Adam Cole
  • 173
  • 1
  • 3
  • 13
  • You probably need this https://stackoverflow.com/questions/10729276/how-can-i-get-the-full-object-in-node-jss-console-log-rather-than-object – 1565986223 Apr 09 '19 at 14:54

1 Answers1

0

You have to get the data from the response object to get the body seen in Postman.

axios.post('todo-lists/getTodoLists', {
      userEmail: this.userEmail
   })
     .then(res => {
        console.log(res.data)
      })
      .catch(err => {
        console.log(err)
      })

The response is the full response containing headers and so on

Adam Cole
  • 173
  • 1
  • 3
  • 13
eikeka
  • 20
  • 6