I'm working to developed API with NodeJS. I got undefined value when I print the value.
Here's my code:
const modelMateris = require("../models/materi");
var Home = {
getHome: (req, res, next) => {
const materisAsync = new Promise((resolve, reject) => {
modelMateris.find({},(err, res) => {
if(err) reject(err);
resolve(res);
});
});
var a = materisAsync
.then(res => console.log(res))
.catch(res => console.log(err));
res.send({code:1000, materis:a });
}
}
module.exports = Home;
I just want to show the output of var A into RESTAPI. So how to print it in NodeJS?