问题
I am trying to run MongoDB server forever locally on Windows 10. And for that I'm using forever server.js which throws an error i.e, Forever is not installed.
I did npm install. But then too showing the same error. I have followed this guide, but it's for Ubuntu. I am using Windows 10.
I need something like if I close the server cmd also, it should keep running.
回答1:
In Windows, you can use the mongod command to register Mongo as a service
mongod --directoryperdb --dbpath "C:\Program Files\MongoDB\Server\3.4\data\db" --logpath "C:\Program Files\MongoDB\Server\3.4\log\mongo.log" --logappend --rest --install
- Open the cmd(command prompt) as administrator
- run the above command
- open services and search for mongo service
- If it is not running already, click start to start the service
回答2:
You need to install mongo as a service. To do so,
- Open cmd in administrator mode.
- Create two directories to store data and logs
mkdir c:\data\db
mkdir c:\data\log
- Create a configuration file. The file must set systemLog.path. Include additional configuration options as appropriate.For example, create a file at C:\Program Files\MongoDB\Server\3.6\mongod.cfg that specifies both systemLog.path and storage.dbPath like this:
systemLog:
destination: file
path: c:\data\log\mongod.log
storage:
dbPath: c:\data\db
install mongo service, run the following command:
mongod.exe --config "C:\Program Files\MongoDB\Server\3.4\mongod.cfg" --install
Start service using:
>net start mongodb
- To stop service use :
>net stop mongodb
- To stop service use :
You can refer official documents here
来源:https://stackoverflow.com/questions/47654689/running-mongodb-forever-using-forever-in-windows