NPM error issues during use-and NPM usage

Source: Internet
Author: User
Tags config json regular expression install node

1. The following is the specific details of the error; Node 8.1.2 Issue: Other space installation succeeded but the installation Webpack always reported the following error: Workaround for reinstalling node


NPM Module Manager

From the JavaScript standard reference tutorial (Alpha), by Nanyi directory introduction NPM init npm set npm config npm info npm search NPM list NPM Install base This usage installs different versions to avoid system privileges NPM UPDATE,NPM uninstall npm run parameter Scripts script commands best practices pre-and post-scripts internal variable wildcard the NPM link npm bin npm adduse R NPM Publish NPM deprecate npm owner other commands npm home,npm repo npm outdated NPM prune npm shrinkwrap Reference link Introduction

NPM has two levels of meaning. One layer of meaning is node's Open module registration and management system, with the URL Another layer of meaning is node's default module manager, which is a command-line software that installs and manages node modules.

NPM does not need to be installed separately. When you install node, NPM is installed together. However, the NPM that came with node may not be the latest version, and it is best to update to the latest version with the following command.

$ NPM Install Npm@latest-g

In the above command, @latest represents the latest version,-G indicates a global installation. So, the backbone of the command is NPM install NPM, which is the use of NPM installation itself. This is possible because NPM itself is no different from the other modules of node.

Then, run the following command to view the various information.

# View NPM command list
$ NPM Help

# See simple usage of individual commands
$ npm-l

# View NPM version
$ npm-v

# View NPM configuration
$ npm confi G List-l
NPM Init

NPM Init Initializes a new Package.json file to be generated. It will ask the user a series of questions, if you feel that you do not have to modify the default configuration, all the way to enter.

If you use-f (on behalf of force),-y (for Yes), skip the question stage and generate a new Package.json file directly.

$ NPM init-y

The NPM set is used to set environment variables.

$ npm Set init-author-name ' Your name '
$ npm set init-author-email ' Your email '
$ npm Set Init-author-url ' http: '
$ npm set init-license ' MIT '

The above command sets the default value for NPM init, and the Package.json author name, Mail, home page, and license fields are automatically written to the preset values when the NPM init is executed. This information will be stored in the user's home directory of the ~/.NPMRC file, so that users do not have to enter each project. If a project has different settings, you can run NPM config for that project.

$ NPM Set Save-exact True

When the above command is set to add a module, Package.json will record the exact version of the module instead of an optional version range. NPM config

$ npm config set prefix $dir

The above command sets the specified $dir directory to the global installation directory of the module. If you currently have write access to this directory, then when running NPM install, you no longer need the sudo command to authorize it.

$ NPM Config Set Save-prefix ~

The above command makes NPM install--save and NPM installs--save-dev when the new module is installed, the allowed version range is changed from the carat sign (^) to the tilde (~), that is, from allowing the minor version to upgrade to only allow the patch package upgrade.

$ npm config set $name
$ npm config set $email

The above command specifies the field default value of the generated Package.json file when using NPM init. NPM Info

The NPM Info command allows you to view specific information for each module. For example, view the information for the underscore module.

$ NPM Info underscore
{name: ' underscore ',
  description: ' javascript\ ' s Functional Programming Helper library. ',
  ' Dist-tags ': {latest: ' 1.5.2 ', stable: ' 1.5.2 '},
   {type: ' git ',
     url: ' git:// Jashkenas/underscore.git '},
  homepage: ' ',
  main: ' Underscore.js ',
  version: ' 1.5.2 ',
  devdependencies: {phantomjs: ' 1.9.0-1 '},
   {type: ' MIT ',
     url: ' https:// '},
   [' underscore.js ',
     ' Underscore-min.js ',
     ' LICENSE '],
  readmefilename: ' '}

The above command returns a JavaScript object that contains details about the underscore module. Each member of this object can be queried directly from the info command.

$ NPM Info Underscore description
JavaScript ' s Functional Programming Helper library.

$ NPM Info Underscore homepage

$ npm Info underscore version
NPM Search

The NPM Search command searches for the NPM repository, which can be followed by a string or regular expression.

$ NPM Search < search terms >

Here is an example.

$ NPM Search Node-gyp
//NAME                  DESCRIPTION
//Autogypi              Autogypi handles dependencies for NODE-GYP Projects.
Grunt-node-gyp        Run node-gyp commands from grunt.
Gyp-io                Temporary solution to let Node-gyp run ' rebuild ' under ...
// ...
NPM List

The NPM List command lists all the modules that are installed for the current project, along with the modules they depend on, in a tree-type structure.

$ NPM List

Together with the global parameter, the globally installed module is listed.

$ NPM List-global

The NPM List command can also list individual modules.

$ NPM List Underscore
NPM Install Basic Usage

The node module is installed with the NPM Install command.

Each module can be "installed globally" or "installed locally." "Global Installation" refers to the installation of a module into the system directory, which can be called by individual projects. Generally, the global installation applies only to tool modules, such as Eslint and gulp. "Local Installation" refers to downloading a module to the Node_modules subdirectory of the current project, and then only in the project directory to invoke the module.

# locally installed
npm install <package name>

# Global Install
$ sudo npm install-global <package name>
$ sudo np M install-g <package name>

NPM install also supports direct input of GitHub code base addresses.

$ NPM Install git://
$ npm Install git://

Before installation, the NPM install checks to see if the specified module already exists in the Node_modules directory. If it does exist, it is no longer reinstalled, even if the remote repository already has a new version.

If you want a module to be forced to reinstall regardless of whether it is installed or not, you can use the-f or the--force parameter.

$ NPM Install <packageName>--force

If you want all modules to be forced to reinstall, remove the Node_modules directory and re-execute the NPM install.

$ RM-RF node_modules
$ npm Install

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.