简体   繁体   English

Bluebird Promise中的Node.js exec mongodb命令

[英]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. 我想使用Promises在node.js中运行mongod命令,以便数据库操作只能在mongodb进程启动后才能运行。 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. 您不应该在node中启动mongod进程,而应该以其他方式进行。 Then you can just check whether it's running, not whether it has started up properly. 然后,您可以检查它是否正在运行,而不是它是否已正确启动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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