簡體   English   中英

Bluebird Promise中的Node.js exec mongodb命令

[英]Nodejs exec mongodb command in Bluebird Promise

我想使用Promises在node.js中運行mongod命令,以便數據庫操作只能在mongodb進程啟動后才能運行。 我嘗試了以下操作,但失敗了:

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進程,而應該以其他方式進行。 然后,您可以檢查它是否正在運行,而不是它是否已正確啟動。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM