What is the difference between local and global module in Node.js? When to use local and global module?

Badal picture Badal · Apr 9, 2015 · Viewed 7.6k times · Source

We can access local module using require function but cannot access global module through it. I read somewhere that to use global module we need to make it local then import it through require function. So if we cannot access global module directly, then what is the need of using it.

Answer

Tomasz Racia picture Tomasz Racia · Apr 9, 2015

You should:

  • Install a module locally if you're going to require() it.
  • Install a module globally if you're going to run it on the command line.