Jan Jůna
Jan Jůna

Reputation: 5074

Using node_modules folder for custom modules

recently I got to project where is this structure:

What do you think about using folder named node_modules for local code which is not fetched from npm?

The only plus is, that you don't have to work with relative paths when requesting module from resource..

Negative part is, that there are many scripts (jshint, nodemon, ..) which are ignoring these folders and also you have to permit this folder also in .gitignore

Upvotes: 1

Views: 2473

Answers (1)

chriskelly
chriskelly

Reputation: 7736

I would call it bad practice for exactly the reason you described. Eventually something will stop working and it will take a long time figure out why.

If you have to work around the relative path problem in node I would go with the supported solution, even if its not ideal, i.e. the NODE_PATH environment variable

NODE_PATH=path\to\program node myprogram.js

There is a good discussion about the alternative options here on github

Upvotes: 1

Related Questions