Dieses Code-Snippet funktioniert perfekt für mich. Bitte versuchen Sie Folgendes:
In main.js
var childprocess = require('child_process');
var child = childprocess.fork(__dirname + '/child');
child.on('message', function(m) {
// Receive results from child process
console.log('received: ', m);
});
In child.js
var User = require('../models/User');
var users= {};
User.find({}, function (err, docs) {
// Please add log in this line to check whether their is anything in database
console.log(docs);
debugger;
users = docs;
process.send(users);
});
Bei mir ergibt sich daraus: