A, npm Introduction
1) npm: node package manager node.js is written in the default package management system js
official website: www.npmjs.com
document: docs.npmjs.com
2) mentioned npm may refer to:
This site npm
npm this js code repository
npm client
3) npm node.js is the default package management systems. After installing node, installed by default npm.
4) npm itself is based on node.js development package (software)
5) Check npm npm current version -v
6) 更新 altitude: altitude above sea level, install latest @ g
Two, npm use (local installation)
1) to find the required packages in https://www.npmjs.com site search
2) in the root directory of the project, the implementation of npm install the package name to install
3) in node.js code by require ( 'package name'); loading the module
Note: by npm install package installation package name, it is automatically downloaded to the current directory at node_modules
4) npm global installation
- npm install the package name -g
- Global Installation of the package is installed as a command-line tool; to be used in the project still need to install this module to this project .
- For example:
// install mime.js by global npm
npm install mime -g
// After installation can be used directly from the command line
MIME a.css
MIME a.doc
- Global npm install actually does two things:
1) Download package to C: \ the Users \ username \ AppData \ Roaming \ NPM \ node_modeles
2) Create command code section executed line
5) npm init [-y] initialization create a package.json
Three, Modules and Packages difference between
1) the package is a file or directory, you must have a package.json to describe, it can be a package
2) any module may be a file or directory, as long as the load can be require by node.js
Four, package.json
1) package.json file: package (or project) profile
package.json common items are:
the name of the package name, item must
release version of the package must Item
description package description
of the author of the package
entrance js files main package, the js file specified by the main field here perform
other packages dependencies dependent
2) How to create package.json
- npm init [-y] Initialization create a package.json; of course also be created manually
- Note: The project root directory can not have Chinese, it is best not to have capital letters
- must contain the name and version fields
Five, package-lock.json document describes the
future npm version 5.x, when the introduction of third-party packages, automatically creates lock.json-Package Penalty for
Package Penalty for-lock.json which contains information about the package to introduce third-party packages so dependent, npm make faster downloads