I'm new to mongodb and nodeJS. Currently I've made a sample application using node.js, monk and mongodb. However to make it work, I have to open 2 cmd windows.The first one is go to mongodb folder, run: mongod --dbpath myprojectpath
. The second is to go to myprojectpath, run: npm start
. Starting mongodb and point to the working path manually seems is not the right way for a web application. But how can I let mongoDB point to my project automatically and run, like SQL server?
It's possible, but keep in mind, that your two mentioned shell calls are different.
The first one will start your mongoDb server with data directory. You could place your datafiles in the default directory (/data/db
) like it's described in the docs. If your datafiles are in the default directory you could simply start it with mongod
that would save you from linking your datafiles.
For a quick startup you could run something like:
#!/bin/sh
mongod;
cd <your project> && node app.js;
To boot up your app.