Starting mongodb server using npm scripts

眉间皱痕 提交于 2021-02-17 06:49:41

问题


I am starting mongodb server using cmd with the following command:

"C:/Program Files/MongoDB/Server/3.6/bin/mongod.exe"

It starts the mongodb server perfectly.

Now I need to do it via npm script. Below is my package.json file:

package.json:

"scripts": {
"ng": "ng",
"prestart": "start /b \"C:/Program Files/MongoDB/Server/3.6/bin/mongod.exe\"",
"start": "ng serve | node server.js",
"build": "ng build --prod",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
}

Now when I hit npm start, it doesn't starts the mongodb server.

I also included the path "C:/Program Files/MongoDB/Server/3.6/bin/mongod.exe" in environment variables (both user&system).

Can anyone help me to know where I was wrong?


回答1:


I read help for the start cmd command and was able to run it in a separate named window:

"scripts": {
    "db": "start \"ToDo MongoDB instance\" /D \"C:/Program Files/MongoDB/Server/4.0/bin/\" mongod.exe --dbpath=\"C:/GIT/NodeJS/todo/db\""
},



回答2:


Try to escape the space in Program Files with a backslash, i.e. Program\ Files. I'm not a Windows guy but I hope this works there as well.

EDIT

As you figured out yourself, you also can enclose the path in (escaped) quotes, then resolving a directory name containing a space should work.




回答3:


This is what worked for me for Windows:

"scripts": {
    "db": "path_to_mongod.exe --dbpath path_to_mongodb-data_folder"
}


来源:https://stackoverflow.com/questions/49686131/starting-mongodb-server-using-npm-scripts

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