Bluebird Promise中的Node.js exec mongodb命令 [英] Nodejs exec mongodb command in Bluebird Promise

查看:53
本文介绍了Bluebird Promise中的Node.js exec mongodb命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Promises在node.js中运行mongod命令,以便数据库操作只能在mongodb进程启动后才能运行.我尝试了以下操作,但失败了:

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

有什么建议吗?

推荐答案

您不应该在node中启动mongod进程,而应该以其他方式进行.然后,您可以检查它是否正在运行,而不是它是否已正确启动.

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.

这篇关于Bluebird Promise中的Node.js exec mongodb命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆