Installation of the NPM for node. js

Source: Internet
Author: User
Tags node server

It was not intended to introduce the installation of NPM for node. JS, but it was found that the management of some of node. JS's packages was implemented via NPM or simply introducing NPM.
1. What is NPM?
NPM is a node package management and distribution tool that has become an unofficial standard for publishing node modules (packages). With NPM, you can quickly find the packages you want to use for a particular service, download, install, and manage the packages you have installed.
2. Installation of NPM (Windows)

[1] We will first configure the NPM Global Module storage path and the path of the cache, for example, I would like to put the above two folder in the Nodejs home directory, under Nodejs to establish "Node_global" and "Node_cache" two folders. Such as


[2] Start cmd, enter

NPM config set prefix "C:\Program files\nodejs\node_global"
And

NPM config set cache "C:\Program Files\nodejs\node_cache"

[3] Now let's install a module to try, choose Express this more common module. Also in the cmd command line, enter "NPM Install Express-g" ("-g" This parameter means to be loaded into the global directory, which is said to set the "C:\Program Files\nodejs\node_global" inside. )。 After the installation process in the CMD is finished scrolling, it will prompt "express" where it is installed, the version and its directory structure. Such as

[4] If there is "XXX is not an internal or external command, is not a running program or batch file" error, you need to set the environment variable under the system variable to create a new "Node_path", enter "C:\Program files\nodejs\node_global\ Node_modules ".

3, Package.json

The NPM command runtime reads the current directory's Package.json file and interprets the file, which is based on the packages/1.1 specification. In this file you can define your app name (name), app description (description), keyword (keywords), version number, app configuration item (config), home page (homepage), author (author), The Resource warehouse address (repository), the address of the bug (bugs), the authorization method (licenses), the directory (directories), the application portal file (main), the command-line file (bin), the application-dependent module (dependencies ), Development environment dependent modules (Devdependencies), run engines (engines), and scripts (scripts).
For developers, the development and release module relies on his correct understanding of the meaning of this file Package.json. Below we use a common example of this article to illustrate:

{    "name": "Test",    "version": "0.1.0",    "description": "A Testing package",    "author": "A messed author <[email protected]> ",    " dependencies ": {        " Express ":" 1.x.x ",        " Ejs ":" 0.4.2 ",        " Redis ":" >= 0.6.7 "    },    " Devdependencies ": {        " vows ":" 0.5.x "    },    " main ":" Index ",    " bin ": {        " test ":"./bin/test.js "    },    " scripts ": {        " start ":" Node Server.js ",        " test ":" Vows Test/*.js ",        " Preinstall ":"./configure ",        " Install ":" Make && make Install "    },    " engines ": {        " node ":" 0.4.x "    }}
4. NPM Common Commands

npm Install <name> installation Nodejs Dependency Pack
For example, NPM install Express installs the latest version of Express by default, or you can install the specified version by adding the version number later, such as NPM install [email protected]

npm Install <name>-G packages are installed in the global environment
But in the code, the direct way through require () is that there is no way to call a globally installed package. The global installation is for the command line, as if the Vmarket is installed globally, you can run the VM command directly on the command line

npm Install <name>--save to write information to Package.json
If you have a Package.json file in the project path, you can use the NPM install method directly to install all the dependent packages based on the dependencies configuration
When this code is submitted to GitHub, it is not necessary to commit the Node_modules folder.

NPM init will guide you through the creation of a Package.json file, including name, version, author information, etc.

npm Remove <name> Remove

NPM update <name> update

NPM ls lists all the packages that are currently installed

NPM root View the installation path for the current package

NPM root-g View the installation path for a global package

NPM Help helps, if you want to view the help of the install command separately, you can use the NPM helper install

Installation of the NPM for node. js

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: info-contact@alibabacloud.com 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.