I am a newbie to nodejs and promises, i am trying to fetch some data from json and pass them to other function for further processing, here is my code.
const test = tests.fetchAll().then(test1 => {
const testsDataArray = JSON.parse(JSON.stringify(test1))
const testsData = testsDataArray.data
const testsId = testsData.find(iid => iid.ips === '1.2.3.4')
// console.log(testsId.id)
console.log(testsId)
return testsId.id.toString()
})
this has a json which is used in the above code
{
id: 36,
name: 'p ',
seats: 10,
description: 'Test description',
contact: 'p@xyz.com',
created_at: '2019-12-31T11:18:19.000Z',
updated_at: null,
ips: '1.2.3.4',
domains: 'xyz.com',
termination_date: null,
seats_used: null
}
when I run the following code :
test.then(result => {
console.log(result)
})
the output printed on console is '36', where as when i return the same, it returns [object Promise]
test.then(result => {
console.log(result)
})