Answer the question
In order to leave comments, you need to log in
Why does console.log work but return doesn't?
Guys, why console.log works, but return doesn't? Writes underfind.
Here is the code
var redisClient = require('../lib/redis');
var getChatData = function() {
redisClient.lrange('messages', 0, 4, function(err, reply) {
reply.map(function(msg) {
return JSON.parse(msg);
})
});
}
module.exports = getChatData;
var HomeModel = require('../models/Home');
console.log(HomeModel());
Answer the question
In order to leave comments, you need to log in
var redisClient = require('../lib/redis');
var getChatData = function () {
return new Promise((resolve, reject) => {
redisClient.lrange('messages', 0, 4, (err, reply) => {
if (err) {
reject(err);
} else {
resolve(reply.map(msg => JSON.parse(msg)));
}
});
});
}
module.exports = getChatData;
(async () => {
try {
const HomeModel = require('../models/Home');
console.log(await HomeModel());
} catch (err) {
console.error(err);
}
})();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question