-3

In the NPM Package Manager Listing for the LEAN Stack Package, it is showing the following for the install directions at the top right of the page:

npm install lean-stack

I need it to say:

npm install -g lean-stack

I have read through the package.json docs and cannot find anything to specify this. I have also set the preferGlobal variable to true in our package.json and that didn't make any difference either.

wayofthefuture
  • 8,339
  • 7
  • 36
  • 53
  • Despite your wishes, the type of installation for a package (global or otherwise) is not up to you. You don't have the right to impose that sort of restriction on the developer. If the developer so chooses to install your package locally (which is recommended), your package should still work. Globally installed packages are as newbish as global variables in source code. – Mulan Jun 30 '16 at 05:06
  • Right but take for example express-generator... it is designed to be used globally. I wouldn't call that newbish I'd call it operating as designed. – wayofthefuture Jun 30 '16 at 05:11
  • Nah, express-generator is newbish too. Anyway, it's beside the point. Any npm user that knows about the `-g` flag and wishes to use it can do so at their own will. You don't need to recommend this as a default. – Mulan Jun 30 '16 at 05:11
  • Draconian policy. Have we not learned from XHTML? – wayofthefuture Jun 30 '16 at 05:16
  • And if that was a legitimate reason, why would they have a preferGlobal flag (https://docs.npmjs.com/files/package.json) and give a warning on local install. Not to mention its only recommended directions they can choose to install locally if they want. – wayofthefuture Jun 30 '16 at 05:24
  • When I go visit the page you link to I see `npm install -g lean-stack` just like you wanted. So what's the problem again?? – Louis Jun 30 '16 at 10:41
  • 1
    Quoting from the npm CEO on this feature request `Yeah, we're never going to do this.` so you should open an issue there to discuss about it but at this time, it's simply impossible to achieve what you want. – HiDeoo Jun 30 '16 at 11:43

2 Answers2

4

Why you can't

Getting to display as npm install packageName -g in the npmjs.com is not possible. you cannot impose people to use your module as global, actually npm does not recommend the use of global modules unless necessary.

Just like how global variables are kind of gross, but also necessary in some cases, global packages are important, but best avoided if not needed.

Additionally, even global modules are used locally in order to freeze package version if you are deploying to other servers etc.

for example, using istanbul for test coverage, you can use the package globally and its simpler to type istanbul test however installing istanbul locally will freeze the version in the package.json file in order to keep it working regardless to updates.

You install it locally and write node node_modules/istanbul/index.js test

istanbul is just an example use-case here.

Displaying a warning:: preferGlobal

If your package is primarily a command-line application that should be installed globally, then set this value to true to provide a warning if it is installed locally.

It doesn't actually prevent users from installing it locally, but it does help prevent some confusion if it doesn't work as expected.

However

setting preferGlobal: true is not enough to trigger a warning when installing locally.

in order to get the message you have to check the following checklist:

  1. valid package.json file.

  2. contains dependencies object in the package.json file (even if it was empty)

You do not see this message in these cases:

  1. if you are in a non-npm project (there is no package.json).

  2. if you are in an npm package-project directory that happens to have the package already installed as a local dependency.

sources:

  1. https://stackoverflow.com/a/28206992/5384679

  2. https://github.com/npm/npm/issues/11652

  3. https://nodejs.org/en/blog/npm/npm-1-0-global-vs-local-installation/

Community
  • 1
  • 1
Bamieh
  • 10,358
  • 4
  • 31
  • 52
  • The OP's question is not about warnings at the time `npm install` is being run but about [this page](https://www.npmjs.com/package/lean-stack) showing an installation command that uses `-g`. The only part of your answer which pertains to the OP's problem is the bit that says to set `preferGlobal` to `true` but the OP indicated in their question that *the OP has already done this.* – Louis Jul 05 '16 at 13:07
  • 1
    @Louis ahh okay, the question is a little misleading, there is no way to put it that way, even only-global libraries do not have this in the npmjs repos. – Bamieh Jul 05 '16 at 14:53
2

It can't be done, but to draw more attention to the global installation option you could use the stats information box like this developer did:

enter image description here

SANBI samples
  • 2,058
  • 2
  • 14
  • 20