Nodejs exec mongodb command in Bluebird Promise

给你一囗甜甜゛ 提交于 2019-12-08 00:49:31

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/32100509/nodejs-exec-mongodb-command-in-bluebird-promise

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!