user3601166
user3601166

Reputation: 127

Where should a mongodb process be started for a node application

I want my application server(Hapi/Express) to start the mongodb process before proceeding with server.start(). A good way to do this is via Promises so that the mongod return code can be captured in .then and checked for start success/failure.


I posted a similar question @ Nodejs exec mongodb command in Bluebird Promise, that prompted me to ask this one here.

Upvotes: 0

Views: 45

Answers (1)

Sergio Tulentsev
Sergio Tulentsev

Reputation: 230481

You seem to not understand the basics of processes.

so that the mongod return code can be captured in .then

mongod will not return any code until it exits (it's called "exit code" for a reason). I assume that you want your mongodb running, so this means no code for you.

Starting a database server from the application is absolutely the wrong way to do it. Database and application should be started separately (by OS' startup manager or whatever). If you install mongodb from a package, the auto-startup should be handled for you (via installing proper init script).

Application should only know a connection string (and if it can't connect to the database at this string, show some pretty error message).

Upvotes: 2

Related Questions