How do I make my NPM package show "npm WARN prefer global" when installing locally

npm install
npm list available packages
create npm package
npm commands
npm list packages in registry
npm install private package
npm list package versions
npm search

Hard to google the subj — too many user questions, mine is about package development. I want a user of my package see "npm WARN prefer global" when installing it not globally.

I thought npm install yo used to have such a warning but now it does not. At least I cannot see it.

My environment:

  › npm --version
1.4.10
  › node -v
v0.10.28

Using npm packages in your projects, For example, to use the lodash package in a Node.js module, in the root directory of the module, create a file named index.js with the following contents:. Install packages from Solution Explorer. The easiest way to install npm packages is through the npm package installation window. To access this window, right-click the npm node in the project and select Install New npm Packages. In this window you can search for a package, specify options, and install.


You need to specify

"preferGlobal": true

in your package.json.

Documentation

npm-ls, Note that nested packages will also show the paths to the specified packages. these are shown in parentheses after the name@version to make it easier for  To share your code with a limited set of users or teams, you can publish private user-scoped or Org-scoped packages to the npm registry. For more information on scopes and private packages, see “About scopes” and “About private packages”.


preferGlobal is now deprecated:

This option used to trigger an npm warning, but it will no longer warn. It is purely there for informational purposes. It is now recommended that you install any binaries as local devDependencies wherever possible.

Creating a package.json file, makes your build reproducible, and therefore easier to share with other developers. Note: To make your package easier to find on the npm website, we  All tutorials about making an npm package, including the official documentation, tell you to enter certain fields in your package.json. We’re going to keep trying to publish our package with as little as possible until it works. It’s a kind of TDD for a minimal npm package.


Creating and publishing private packages, To see your private package page, visit https://npmjs.com/package/package-name, replacing package-name with the name of your package. Private packages will say private below the package name on the npm website. For more information on the publish command, see the CLI documentation. This means publishing a package involves many steps. At the very least, you need to: Run tests (if there are any) Update version in package.json according to Semver. Create a git tag according to Semver. Push the package to Github. Push the package to npm. Create release notes for every update.


Creating Node.js modules, To create a package.json file, on the command line, in the root  When npm installs a package, it keeps a copy, so the next time you want to install that package, it doesn’t need to hit the network. The copies are cached in the .npm directory in your home path:


Creating and publishing scoped public packages, npmrc <profile-name>. On the command line, create a directory for your package: mkdir my-test-package. Navigate to the  As I said at the beginning of this article I can't believe I published my first npm package this weekend. I just never really had a need to do so until now but I was really excited to learn how easy it was. If this is your first npm package please leave me some comments or tweet at me when yours is live! Happy Coding! Dan