Answer the question
In order to leave comments, you need to log in
How to store local data in a variable?
I welcome everyone!
Congratulations to everyone on NG or almost NG, I don’t know how much you have left, 48, 24, 12 hours.
Okay, comrades, I have such a problem. I get data from the database, everything is saved, but when I display the variable of the main function (obj), in the function where I save it, everything is fine, but where the return (at the end of the function) is for some reason an empty object ... How so?
Here is the function code:
const findOrCreate = (id) => {
const token = cookie.parse(socket.request.headers.cookie)['token']
let obj = []
if (!token) {
obj = { username: username, id: socket.id, position: { lat, lng }, selected: 'man', data: '', country, avatar: ava_path }
usr.pus(res)
} else {
const db = new PouchDB('http://127.0.0.1:5984/pp4_db')
db.get('user')
.then(function(doc) {
const user_d = JSON.parse(doc.user)
obj = user_d
})
.catch(function (err) {
return err
})
}
console.log(obj)
return users.find(user => user.id === id) || createUser(obj)
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question