0

I know this isn't necessarily a "great" SO question, but I don't know where else to turn... (if you do, let me know in the comments!).

I am developing a web application that uses Node.js not even as a web server, but strictly to execute build tools. So, I use NPM to install grunt, cssmin, some testing tools, and some other stuff. At this point I have used -g ('global') during the install phase from time to time, not really knowing any better because I'm new to Node and sometimes the instructions tell me to do this.

Now I'm at the stage to do an initial check-in to our code repository. In theory, another developer could "check it out" and run with it. But that's where I get confused.

How do I ... encapsulate...? all of my Node.js stuff such that it's portable? Ideally the other developer would simply install Node (if they haven't already), type grunt dist into the command line, and it would build all the distributatbles for them. But obviously that won't be the case unless by coincidence they have already installed all the appropriate tools...?

I THINK this might be what I have to do going forward, but I would like some insight or suggestions on best practices:

  1. Install Node (of course!)
  2. NPM install required package (such as grunt), NOT using the global flag but using --save
  3. Check-in the application folder and its contents

Then the next developer would:

  1. Install Node (of course!)
  2. Check out the module from source control
  3. Navigate to the checked-out folder and npm install, which should theoretically "register" the dependencies with their local instance of Node.js? (this is the part I'm unsure of)
  4. Profit. They can now do things like grunt dist and the Grunt task should run as expected

Does this sound reasonable? Are there additional factors I'm missing?

Greg Pettit
  • 10,749
  • 5
  • 53
  • 72
  • You are right, just a note for the step 3 for the next developer, he is not registering the dependencies with `npm install`, he is actually installing all dependencies. I mean, he is downloading to the `npm_modules` folder all needed files that you already have registered into your `package.json`. You should also remember to add your `node_modules` folder to the `.gitignore` file (or add it to the list of ignored files of whatever source control you use). – Gepser Hoil Jun 25 '15 at 17:31
  • Thanks, Gepser. I was assuming that I would be checking in node_modules so that the developer would be guaranteed to be using the same versions as those checked in. Is that a false assumption? Ie. Will node use the local node_modules instead of downloading them? – Greg Pettit Jun 25 '15 at 17:37
  • Interesting that you would check in the `node_modules` folder. Usually the `package.json` file would hold the exact versions of the packages you need, and you could just `npm install` that. All `npm install` does is download the dependencies into the `node_modules` folder so if you do decide to check it in, the other developer does not need to `npm install`. – Patosai Jun 25 '15 at 18:05
  • Maybe you want to read this answer (2 days ago) about how global and local packages works http://stackoverflow.com/questions/31008187/npm-on-osx-error-getting-global-installed-packages/31009698#31009698 – Gepser Hoil Jun 25 '15 at 18:12
  • @Patosai if the other developer would get the exact versions, that actually makes me reconsider! I had been imagining they would get "the latest" version. The only other reason to check in the local at that point would be so that you don't have to depend on the repository staying available (in terms of connectivity as well as just having the package kept online). – Greg Pettit Jun 25 '15 at 21:29
  • I tried testing this and had spotty results. I had to manually npm-install some stuff and I can't even figure out why. – Greg Pettit Jul 03 '15 at 19:48

0 Answers0