I have no idea why exported function findChilds
return undefined
Function look like this:
const Folder = module.exports = mongoose.model('folder', FolderSchema);
module.exports = {
findChilds: (folderId) => {
Folder.find({
parent: folderId
}).then((childs => {
childs.forEach((child => {
module.exports.findChilds(child._id)
}));
return childs;
}));
}
};
And calling:
const folderModel = require('../models/Folder');
router.get('/remove/:id', (req, res) => {
let functionResult=folderModel.findChilds(req.params.id);
console.log(functionResult)
});
functionResult
show only undefined.