How to fetch the details from mongo db and send or store in object in nodejs Fork method

前端 未结 1 1227
终归单人心
终归单人心 2020-12-22 11:59

Here I am using fork method to do some calculation in node js. I have followed by the answer in link.It worked as expected and had started to do calculation.

Here ho

相关标签:
1条回答
  • 2020-12-22 12:03

    This code snippet works perfectly for me. Please try this:

    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);              
    });
    

    For me this results:

    0 讨论(0)
提交回复
热议问题