2

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?

r0-
  • 2,388
  • 1
  • 24
  • 29
user1424258
  • 97
  • 1
  • 1
  • 10

1 Answers1

1

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.

r0-
  • 2,388
  • 1
  • 24
  • 29
  • If datafiles are under /data/db, how could my project(node.js) know this path? Do I need to setup in app.js or somewhere? Sorry I'm not that clear of the workflow. – user1424258 Aug 11 '14 at 18:03
  • No, the call `mongod`will start your mongodatabase - the datafiles belong to this process (your mongoDb database). The node process (your app.js) is just the application that will connect to the database. they are separated process. You can use your `node app.js`just as usual. – r0- Aug 11 '14 at 18:24