启动mongodb和express的正确方法? [英] Correct way of starting mongodb and express?
问题描述
我有一个可以在express上运行并与mongodb通信的应用程序.这是我启动应用程序的方式:
I have an app which runs on express and communicates with mongodb. This is how I start my app:
1.启动Mongodb
mongod --dbpath data --config mongo.conf"
2.启动Express
node server.js
我的问题是,有没有办法将这些结合起来?我知道节点是单线程的,所以我们不能同时从server.js运行express和mongo,但是正确的方法是什么?可以使用npm从JavaScript文件启动mongo吗?
My question is, Is there a way to combine these? I know node is single threaded so we cant run both express and mongo from server.js but what is the correct way? Is it possible to start mongo from a javascript file using npm?
我可以在两个不同的命令提示符下分别运行 mongo --dbpath数据和 node server.js .我的问题是从一个文件(如果可能)启动它们.
I can run mongod --dbpath data and node server.js separately on two different command prompt. My question is to start them from one file (if possible).
推荐答案
start
在Windows中创建新的cmd
这是我的配置:
start
creates new cmd in windows
here is my config:
"scripts": {
"prestart": "start mongod --config ./data/mongod.cfg",
"start": "node ./server/bin/www",
"poststart": "start mongo admin --eval \"db.getSiblingDB('admin').shutdownServer()\"",
"pretest": "start mongod --dbpath data",
"test": "mocha test",
"posttest": "start mongo admin --eval \"db.getSiblingDB('admin').shutdownServer()\""
},
祝你好运!
这篇关于启动mongodb和express的正确方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!