What to put for NPM scripts when developers are on multiple systems?

Viewed 34

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?

2 Answers

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?

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

Related