2

is there a way to use the globally installed moduled directly without declaring package.json and/or installing the modules in the current directory? i.e Just like a batch/shell job, running a small script with just a file itself..

Let me give you the context, in my job I keep getting various request like currently I am processing some file manually, I usually write script for these tasks comprising for few 10 to 20 lines to make things easy for me and save few hours. Though the script is probably never be gonna used again. To manage the dependent module, I either declare them in package.json or install locally one by one by using npm install <package-name>. It will be very handy if I can achieve it with a single js file like a shell/batch script.

I guess this would be possible if somehow my script is able to refer a global modules.

old-monk
  • 799
  • 8
  • 20
  • Possible duplicate of [NodeJS require a global module/package](https://stackoverflow.com/questions/15636367/nodejs-require-a-global-module-package) – RobC Mar 04 '19 at 10:47

1 Answers1

3

You can use npm link in your project folder without installing the module locally.

npm link <module>

Alternatively you can also use NODE_PATH env variable to tell your scripts where your globally installed packages are, this way accessing them as they were local.

mexo
  • 242
  • 2
  • 9