"node_modules" for private modules that need to be committed?

454 views
Skip to first unread message

Tom

unread,
Oct 10, 2012, 11:09:27 AM10/10/12
to nod...@googlegroups.com
I've added the node_modules folder to my .gitignore file, which works fine thanks to NPM Shrinkwrap (after deploying I need to run npm install using the shrinkwrap.json file).

However, I've got some private modules now that I won't publish to NPM. I would like to require these modules like the other modules in node_modules.

Unfortunately I cannot put these modules in node_modules, because they'd be ignored by git, messing with my future deployment.

Where should I place these modules instead? I've been told that editing the paths variable for node's module lookup is highly unrecommended.

Note that these are small undocumented nonpublic modules, which is why I don't want to publish them to NPM.

Tom

Diogo Resende

unread,
Oct 10, 2012, 11:31:36 AM10/10/12
to nod...@googlegroups.com
You have 2 choices:

1. Change your .gitignore
2. Change your require() calls

Example for 1:
(instead of having "node_modules")

node_modules/a
node_modules/b
...

Example for 2:
(in case you put your module in priv_modules)

var xpto = require("./priv_modules/xpto");

-- 
Diogo Resende

--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Jeff Barczewski

unread,
Oct 10, 2012, 11:40:54 AM10/10/12
to nod...@googlegroups.com
If you are ok with putting them in github then you can just add dependency that points to a github tarball, for example

"dependencies": {
}

where TAG is a named git tag (version), a branch name, or a commit sha. I would recommend using a named git tag (version) for best flexibility.

Once you have added something to package.json, you can install simply be doing `npm install` and it will pull it down from github as a tarball just as if it came from npm.

Tom

unread,
Oct 10, 2012, 11:44:58 AM10/10/12
to nod...@googlegroups.com
Thanks.

I think I will simply go with changing my .gitignore to list all NPM published modules, assuming this is acceptable behavior.

Tom

Op woensdag 10 oktober 2012 22:32:13 UTC+7 schreef Diogo Resende het volgende:

Roly Fentanes

unread,
Oct 10, 2012, 12:33:09 PM10/10/12
to nod...@googlegroups.com
For private github repos

git+ssh://g...@github.com:username/repo.git

mgutz

unread,
Oct 10, 2012, 1:51:19 PM10/10/12
to nod...@googlegroups.com
I suggest using a proper git repository. Use bitbucket.org who provides free private repos, and reference them in your package json like this

git+ssh://g...@bitbucket.org:USER/PROJECT.git


On Wednesday, October 10, 2012 8:09:27 AM UTC-7, Tom wrote:

Alex Kocharin

unread,
Oct 10, 2012, 2:02:03 PM10/10/12
to nod...@googlegroups.com
Tom,
 
If you want it to be managed by npm, use git+ssh:// scheme, that works. But there are several issues with that. For example, if you use npm update, it will try to update your private package from repository. And if there's a package with the same name, you will have trouble.
 
Another way is to put these packages to another folder, say my_modules and invoke node.js with node_path env like that:
NODE_PATH=my_modules node server.js
This way you can safely separate private modules from the public ones.
--
// alex
 
 
10.10.2012, 19:09, "Tom" <tomm...@gmail.com>:
--

Julian Gruber

unread,
Oct 11, 2012, 2:52:40 AM10/11/12
to nod...@googlegroups.com
use /lib or put modules in a git repo (you can host them yourself too) and reference them with git:// or git+http://.

Charles Care

unread,
Oct 11, 2012, 3:51:42 AM10/11/12
to nod...@googlegroups.com
I had to do this a couple of months ago, and I found that using a private repo for code and building tagged releases using "npm pack" worked well for me. 

The company I was working for stored all of its deployment packages in Amazon S3. We considered using the git+ssh approach, but our general approach to managing releases (with other technologies) was to build archival packages, so installing from a tarball worked well for us.

At the time I put together a simple module to support the workflow we were using: https://github.com/ccare/node-release-utils

Cheers,

Charles

On 11 October 2012 07:52, Julian Gruber <miste...@googlemail.com> wrote:
use /lib or put modules in a git repo (you can host them yourself too) and reference them with git:// or git+http://.

Mariusz Nowak

unread,
Oct 11, 2012, 4:37:39 AM10/11/12
to nod...@googlegroups.com
Tom:

Have you tried following in .gitignore:

node_modules/*
!node_modules/my-private-package1
!node_modules/my-private-package2

Aseem Kishore

unread,
Oct 12, 2012, 12:27:20 PM10/12/12
to nod...@googlegroups.com
Surprised no one has mentioned this yet:

You can .gitignore node_modules but still manually check in files under node_modules. Git will just ask you to add a -f flag if you really mean to check those in.

We do this for our own private modules. (Actually, what we check into node_modules are just symlinks. Our modules live in their own directories alongside the requiring module.)

Aseem

--

Isaac Schlueter

unread,
Oct 12, 2012, 4:36:19 PM10/12/12
to nod...@googlegroups.com
You can also put something like this in .gitignore:

```.gitignore
node_modules
!node_modules/foo
```

and it'll ignore everything in node_modules *except* node_modules/foo.
Reply all
Reply to author
Forward
0 new messages