0

Currently I have a tool setup that will launch Mongod, following the advice of this post.

However, the issue is that when I have my configuration setup to run this Mongod tool before launching, it won't run my node script since there's no "successful completion" by Mongod.

Is there any way around this? In other words, can I have mongod start alongside my configuration but not block my script from running until it "completes"?

rb612
  • 5,280
  • 3
  • 30
  • 68
  • I would advise not to run a database server instance in such a way in the first place. A database server is not something you "start for each build" but rather a service which your application should be talking to. Generally it "should be running" before you even open your IDE. On most *nix based systems it is actually installed and run as a service by default. On Windows there are "optional" instructions, but really that "option" should be followed almost all of the time. – Neil Lunn May 13 '18 at 07:55
  • @NeilLunn thanks! I’m definitely new to webdev so I’m wanting to do the most appropriate practice. So do developers just generally run mongod and then open their IDE each session? And it just stays running through the development session? – rb612 May 13 '18 at 07:58
  • Speaking for myself, any database server is typically already running. Sometimes in it's own VM or container. This is what happens in the real world so it's generally best to develop in a way that "closely mimics" what will actually happen in production deployment. If this were Oracle or SQL Server you would not even be given the "option". Read the installation instructions and get the database running as a service. – Neil Lunn May 13 '18 at 08:01
  • @NeilLunn so just to make sure I understand, as a Mac user if it’s running as a service, I should just have to run Mongod once and then it’ll stay running until I restart my computer? In other words, it persists through multiple login sessions? – rb612 May 13 '18 at 08:06
  • 1
    Yes. See https://stackoverflow.com/questions/5596521/what-is-the-correct-way-to-start-a-mongod-service-on-linux-os-x And then you also really should get authentication enabled as well. Your "real world" app will need and use authentication with the database, so now is as good a time to start as any. – Neil Lunn May 13 '18 at 08:09
  • @NeilLunn thanks for your help. I’ll read up on MongoDB authentication next. – rb612 May 13 '18 at 08:11
  • I‘d even go a few steps further and use either [Vagrant (VM-based)](https://www.vagrantup.com) or [docker-compose (container-based)](https://docs.docker.com/compose/) to come as close to the production environment and set up a replicated and/or sharded environment. Extra points for provisioning the vagrant boxes with puppet, chef or (my preferred) ansible. You can take those recipes/playbooks or compose.yml to make sure your production environment is configured according to your needs with no extra effort involved. – Markus W Mahlberg May 13 '18 at 09:32

0 Answers0