I have this function
const run = async () => {
await LOLUserData.LOLUserData(3)
const LOLUserDataResult = await LOLUserData.LOLUserData()
console.log(LOLUserDataResult)
await app.listen(PORT, () => {
console.log(`Arena Gaming Server is listening on port ${PORT}!`)
})
}
which sends data to this function on startup
//=============================================================================
// [Mongoose] Get Active Sessions users data [userId, IGN, LOLSummonerId, LOLRegion] {Step (2)} {League of Legends Tracking}
//=============================================================================
const User = require('../../models/user')
const getLOLUserData = (userId) => {
// Get User data if (valid userId & IGN exsists)
User.findOne({'userId': userId, $and: [ { IGN: { $ne: '' , $exists: true} } ]})
.then(user => {
return ( [
user.userId,
user.IGN,
user.LOLRegion,
user.LOLSummonerId
])
} )
.catch(err => {
console.log(err)
})
};
exports.LOLUserData = getLOLUserData
The const LOLUserDataResult = await LOLUserData.LOLUserData()
console.log(LOLUserDataResult)
Should return the array from the previous function but instead i get an error
TypeError: Cannot read property 'userId' of null
What am I doing wrong here?