How to determine if the current npm package is global?

I want to write code that will be executed by npm postinstall only if the package is installed globally. Is there an integrated detection solution if the active package is installed globally?

If not, what is the best workaround that will work on any OS? My only idea at this time is to check the current working directory of the package and see if it is under the npm global route.

+4
source share
2 answers

I found the solution I was looking for in this repo .

!!process.env.npm_config_global postinstall script. , .

+4

require.resolve(), . , , . npm root -g, .

https://nodejs.org/api/globals.html#globals_require_resolve

0

All Articles