简体   繁体   中英

Nodejs exec mongodb command in Bluebird Promise

I want to run mongod command in node.js using Promises, so that database operations can run only after mongodb process is started. I tried my hands with following, but failed:

var Promise = require("bluebird");

var execAsync = Promise.promisify(require('child_process').exec);

execAsync("~/mongodb/bin/mongod").then(function(result){
    console.log("started mongodb...");
}).catch(function(error){
    console.log("error in starting mongodb..."+JSON.stringify(error));
});

Any suggestions?

You shouldn't start your mongod process in node, you should be doing it some other way. Then you can just check whether it's running, not whether it has started up properly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM