1

recently I got to project where is this structure:

  • app.js <- init script, which will start lib/index.js
  • node_modules <- Modules fetched from npm
  • lib
    • index.js
    • resources - some code for entities in system
    • node_modules - local modules used in system (not from npm)

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

Jan Jůna
  • 4,965
  • 3
  • 21
  • 27

1 Answers1

1

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

chriskelly
  • 7,526
  • 3
  • 32
  • 50