Ekin Koc
Ekin Koc

Reputation: 2997

How to manage internal Node.JS modules

What would be the preferred way to handle internal modules within a node.js application?

I mean, currently we have a fairly big application and there are several dependencies, installed via npm. We have node_modules in .gitignore. Therefore it's not in the repository. We use npm shrinkwrap to freeze the modules versions, so, upon deployment, an npm install puts together eveything we need into node_modules.

The problem is, since out app is getting bigger, we want to split it to smaller modules. Now, if I create a foo module and put it in node_modues, I need to allow it in the repo, which does not seem so neat to have both ignored and checked out modules in node_modules.

We can not publish these on npm registry because they are not really "public".

Is there any obvious solution that I'm not aware of?

Upvotes: 8

Views: 5275

Answers (2)

Michelle Tilley
Michelle Tilley

Reputation: 159105

A common solution is to store the modules in a private Git repository somewhere, and then use a git:// URL as a dependency; npm knows how to clone repositories as dependencies.

Upvotes: 5

david van brink
david van brink

Reputation: 3642

I agree with your aesthetic of not mixing 3rd-party non-repo stuff with your in-house revision-controlled contents.

The NODE_PATH search path variable can help you here, you can use a different directory with contents under revision control.

http://nodejs.org/api/modules.html

Depending on your appetite for flexibility vs complexity, you can consider a build step that actually copies your various node modules from wherever you keep them, into an output directory (probably "named node_modules" but not necessarily).

Upvotes: 7

Related Questions