Install node. js npm and node. jsnpm

Source: Internet
Author: User
Tags install node node server

Install node. js npm and node. jsnpm
I didn't plan to introduce the npm installation of node. js, but I found that the management of some node. js packages is implemented through npm. I 'd like to briefly introduce npm.
1. What is npm?
Npm is a node package management and distribution tool and has become an unofficial standard for releasing node modules (packages. With npm, you can quickly find the packages to be used by specific services, download, install and manage installed packages.
2. npm installation (windows)

[1] First, we need to configure the npm global module storage path and cache path. For example, I want to put the above two folders in the main directory of NodeJS, create the "node_global" and "node_cache" folders under NodeJs. For example


[2] Start cmd and 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 try installing a module and select express, a common module. Similarly, in the cmd command line, enter "npm install express-g" ("-g" indicates that the parameter is installed in the global directory, that is, the "C: \ Program Files \ nodejs \ node_global .). After the installation process in cmd is rolled over, the system will prompt "express" which is installed, the version, and its directory structure. For example

[4] if the error "xxx is not an internal or external command, or a program or batch file that can be run" exists, you need to set the environment variable to create "NODE_PATH" under the system variable ", enter "C: \ Program Files \ nodejs \ node_global \ node_modules ".

3. package. json

When running the npm command, the package. json file in the current directory is read and interpreted. This file is based on the Packages/1.1 specification. In this file, you can define your application name, description, key words, version, and config) home Page (homepage), author (author), Resource repository address (repository), bug submission address (bugs), authorization method (licenses), directory (directories) main, bin, dependencies, devDependencies, engines, and scripts).
For developers, the development and release modules depend on their correct understanding of the meaning of the package. json file. Here is an example shared in this article:

{    "name": "test",    "version": "0.1.0",    "description": "A testing package",    "author": "A messed author <messed@example.com>",    "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. Common npm commands

Npm install <name>Install the nodejs dependency package
For example, npm install express will install the latest version of express by default, you can also install the specified version by adding a version number later, such as npm install express@3.0.6

Npm install <name>-gInstall the package in the global environment
However, in the Code, there is no way to call the global installation package directly by using require. Global installation is for the command line. It is like after vmarket is installed globally, you can directly run vm commands in the command line.

Npm install <name> -- saveDuring installation, the information is written to package. json.
If the package. json file exists in the project path, you can directly use the npm install method to install all the dependency packages according to the dependencies configuration.
When the code is submitted to github, you do not need to submit the node_modules folder.

Npm initThis will guide you through creating a package. json file, including the name, version, and author information.

Npm remove <name>Remove

Npm update <name>Update

Npm lsList all packages currently installed

Npm rootView the installation path of the current package

Npm root-gView the installation path of the global package

Npm helpTo view the help of the install command separately, you can use the npm help install


Nodejs npm Problems

C: \ Users \ Administrator \ AppData \ Roaming \ create an npm folder in this directory.

Nodejs npm displays invalid commands

Find the node installation directory. Find the npm command. Place the path in the environment variable.

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.