How to tell if npm package was installed globally or locally

后端 未结 6 1324
遇见更好的自我
遇见更好的自我 2020-12-22 17:25

I am installing grunt, node, npm, bower, and grunt-cli on windows7.

The instructions say i should run the install commands with -g flag for global.

How can I

6条回答
  •  醉酒成梦
    2020-12-22 17:41

    From your package with sindresorhus/is-installed-globally

    https://github.com/sindresorhus/is-installed-globally

    Usage:

    const isInstalledGlobally = require('is-installed-globally');
    
    // With `npm install your-package`
    console.log(isInstalledGlobally);
    //=> false
    
    // With `npm install --global your-package`
    console.log(isInstalledGlobally);
    //=> true
    

    I found this useful when I had to distribute prebuilt files with my package: How to publish a npm package with distribution files? With this package, I can check if the installation is local or global, and then use relative paths for local installations, as shown here.

提交回复
热议问题