5

Same title.

I don't want install every time with any project.

Just install once.

Thanks in advance.

Edit: I know install global but how to require it is my question.

Hongkiat
  • 76
  • 1
  • 1
  • 8
  • 1
    Possible duplicate of [How do I install a module globally using npm?](https://stackoverflow.com/questions/5817874/how-do-i-install-a-module-globally-using-npm) – TommyBs Oct 17 '18 at 10:18
  • 1
    You can install globally - https://stackoverflow.com/questions/5817874/how-do-i-install-a-module-globally-using-npm But look carefully at the reasons you would do this. It does not make sense for something you might require especially as if you need to update it for one project you could update it for all with unintended consequences. – TommyBs Oct 17 '18 at 10:18
  • Just going to echo what's said above – you really probably don't want to do this, no matter how annoying it might feel to type in that `npm i --save something` for every project. – AKX Oct 17 '18 at 10:25
  • I think his mean is call `require` – hong4rc Oct 17 '18 at 10:40

3 Answers3

1

Check Addenda: Package Manager Tips Define NODE_PATH with path local modules, example:

  • /usr/lib/node_modules
  • C:\Users\<Username>\AppData\Local\Yarn\Data\global\node_modules
  • Or anywhere you want

And now you can call it.

Since the module lookups using node_modules folders are all relative, and based on the real path of the files making the calls to require(), the packages themselves can be anywhere.

hong4rc
  • 3,999
  • 4
  • 21
  • 40
0

Yes. possible. Install all the modules globally. ie; npm install -g <module_name>

Then use it in your application as necessary.

But, this method is not advised.

Jacob Nelson
  • 2,370
  • 23
  • 35
0

After you install them global, use npm link in project folder with package names(see npm link), to link them to that project. e.g. if your project requires lodash use npm link lodash.

Another way, if you want to have multiple little scripts(e.g. not projects) you can set the NODE_PATH variable with path to where your npm stores global packages. And after that require('<global-module>') will work without link and installing node_modules into folder.

BladeMight
  • 2,670
  • 2
  • 21
  • 35