2

I have a web app project, and it uses Mongo, so one of my NPM scripts is "start-mongo-dev": "mongod", for spinning up the Mongo daemon during development.

I used to use OSX, but just got a new computer and run Linux Ubuntu. Now the command to begin the daemon is sudo service mongod start, so it would seem I should change the NPM script to that.

But that is a red flag. What if I go back to the old computer at all? What if I collaborate on this project with someone who uses OSX?

In short, how is one expected to handle developing with multiple OS's?

tscizzle
  • 11,191
  • 15
  • 54
  • 88
  • 1
    One option is to stick with things that can be installed as Node modules and then just run those commands since they _should_ work cross-platform without issue. – Matthew Herbst Jan 10 '19 at 21:25

2 Answers2

3

Ian's solution may be better but one alternative would be to create a bash script inside your project that detects the OS and runs the appropriate command. You can find more info on how to do that here How to detect the OS from a Bash script?

schu34
  • 965
  • 7
  • 25
1

In some packages, I see divisions like this indicated with a :. For example:

"scripts": {
  "start-mongo-dev:osx": "mongod",
  "start-mongo-dev:ubuntu": "sudo service mongod start"
}

I am not aware of a canonical solution, but that doesn't mean there isn't one. I happen to like this one, though. #opinion

Ian MacDonald
  • 13,472
  • 2
  • 30
  • 51