In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
What is npm?
NPM, whose full name is Node Package Manager, is a package management and distribution tool installed with NodeJS. It makes it easy for JavaScript developers to download, install, upload, and manage installed packages.
Npm install installation module
Basic grammar
Npm install (with no args, in package dir) npm install [/] npm install [/] @ npm install npm install npm install alias: npm icommon options: [- S |-- save |-- D |-- save-dev |-- O |-- save-optional] [- E |-- save-exact] [--dry-run]
Install the package. The latest version is installed by default.
Npm install gulp
Install the specified version
Npm install gulp@3.9.1
Install the package and keep the information in the package.json file of the project
The project's dependence on modules can be expressed in the following three ways (assuming the current version number is 1.1.0):
Newly released patch versions of compatible modules: ~ 1.1.0, 1.1.x, 1.1
Newly released minor versions and patches of compatible modules: ^ 1.1.0, 1.x, 1
Compatibility module newly released major version, minor version, patch version: *, x
-S,-- save installation package information will be added to dependencies (production phase dependency)
Npm install gulp-save or npm install gulp-S
The dependencies field of the package.json file:
"dependencies": {"gulp": "^ 3.9.1"}
-D,-- save-dev installation package information will be added to devDependencies (dependencies in the development phase), so it is generally used during the development phase
Npm install gulp-save-dev or npm install gulp-D
The devDependencies field of the package.json file:
"devDependencies": {"gulp": "^ 3.9.1"}
-O,-- save-optional installation package information will be added to optionalDependencies (optional phase dependency)
Npm install gulp-save-optional or npm install gulp-O
The optionalDependencies field of the package.json file:
"optionalDependencies": {"gulp": "^ 3.9.1"}
-E,-- save-exact precisely installs the specified module version
Npm install gulp-save-exact or npm install gulp-E
Enter the command npm install gulp-ES and notice the dependencies field of the package.json file to see that the ^ in the version number has disappeared
"dependencies": {"gulp": "3.9.1"}
After the dependencies of the module are written into the package.json file, others open the root directory of the project (project open source, internal team cooperation), and use the npm install command to install all dependent packages according to the dependencies configuration.
Npm install
Local installation (local)
Npm install gulp
Global installation (global), using-g or-- global
Npm install gulp-gnpm uninstall uninstall module
Basic grammar
Npm uninstall [/] [@]... [- S |-- save |-D |-- save-dev |-O |-- save-optional] aliases: remove, rm, r, un, unlink
For example, uninstall the development version of the module
Npm uninstall gulp-save-devnpm update update module
Basic grammar
Npm update [- g] [...] npm outdated checks whether the module is out of date
Basic grammar
Npm outdated [[/]...]
This command lists all packages that are out of date and can be updated in a timely manner.
Npm ls to view installed modules
Basic grammar
Npm ls [[/]...] aliases: list, la, ll
View globally installed modules and dependencies
Npm ls-gnpm init guides the creation of a package.json file in the project
The information of the installation package can be kept in the package.json file of the project so that it can be used by other project developers or in cooperation with others. It is also said that package.json is essential in the project.
Npm init [- f |-- force |-y |-- yes]
Npm help to view detailed help for a command
Basic grammar
Npm help []
For example, enter npm help install, and the system opens the file / nodejs/node_modules/npm/html/doc/cli/npm-install.html of the local nodejs installation package in the default browser or default editor.
Npm help installnpm root view the installation path of the package
The path to the output node_modules
Npm root [- g] npm config manages the configuration path of npm
Basic grammar
Npm config set [- g |-- global] npm config get npm config delete npm config listnpm config editnpm get npm set [- g |-- global]
The most important thing to use for config is to set up agents to solve the problem that npm failed to install some modules.
For example, when I am in the company's intranet, I cannot complete the installation of any modules because of the company's firewall. Setting up an agent at this time can solve the problem.
Npm config set proxy= http://dev-proxy.oa.com:8080
As another example of the domestic network environment, an official IP may be harmonized. Fortunately, there are well-intentioned people in China who have set up an image. At this time, we simply set up an image.
Npm config set registry= "http://r.cnpmjs.org"
It can also be configured temporarily, such as installing Taobao image.
Npm install-g cnpm-caching of the registry= https://registry.npm.taobao.orgnpm cache management module
Basic grammar
Npm cache add npm cache add npm cache add npm cache add @ npm cache ls [] npm cache clean []
The most common command is nothing more than clearing the npm local cache
Npm cache cleannpm start startup module
Basic grammar
Npm start [-]
This command is written in the start field of the package.json file scripts. You can customize the command to configure a server environment and install a series of necessary programs, such as
"scripts": {"start": "gulp-ws"}
Entering the npm start command in cmd at this point is equivalent to executing the watch and server commands customized by the gulpfile.js file.
If start is not set in the package.json file, node server.js will be started directly
Npm stop stop module
Basic grammar
Npm stop [-] npm restart restart module
Basic grammar
Npm restart [-] npm test test module
Basic grammar
Npm test [-] npm tst [- -]
The command is written in the test field of the package.json file scripts, and can be customized to perform some operations, such as
"scripts": {"test": "gulp release"}
Entering the npm test command in cmd at this point is equivalent to executing the release command customized by the gulpfile.js file.
Npm version View Module version
Basic grammar
Npm version [| major | minor | patch | premajor | preminor | prepatch | prerelease | from-git] 'npm [- v |-- version]' to print npm version'npm view version' to view a package's published version'npm ls' to inspect current package/dependency versions
View the version of the module
Npm version
Npm view view the registration information of the module
Basic grammar
Npm view [/] [@] [[.]...] aliases: info, show, v
View the dependency of the module
Npm view gulp dependencies
View the source file address of the module
Npm view gulp repository.url
View the contributor of the module, including the email address
Npm view npm contributorsnpm adduser user login
Basic grammar
Npm adduser [--registry=url] [--scope=@orgname] [--always-auth]
You need to log in before publishing the template to the npm community, and then enter the publishing operation
Npm publish release module
Basic grammar
Npm publish [|] [--tag] [--access] Publishes'.' If no argument suppliedSets tag 'latest' if no-- tag specifiednpm access sets the access level on the published package
Basic grammar
Npm access public [] npm access restricted [] npm access grant [] npm access revoke [] npm access ls-packages [| |] npm access ls-collaborators [[]] npm access edit []
Syntax of npm package.json
English original: https://docs.npmjs.com/files/package.json
There is a lot of content in this piece, and some kind-hearted people in China have organized it: "npm package.json Chinese document". Copy some common ones from this document, as follows:
Default value
Npm sets some default values based on the contents of the package.
"scripts": {"start": "node server.js"}
If the root directory of the package has a server.js file, npm sets the start command to node server.js by default.
"scripts": {"preinstall": "node-waf clean | | true; node-waf configure build"}
If the root directory of the package has a wscript file, npm compiles the preinstall command with node-waf by default.
"scripts": {"preinstall": "node-gyp rebuild"}
If the root directory of the package has a binding.gyp file, npm compiles the preinstall command with node-gyp by default.
"contributors": [...]
If the root directory of the package has an AUTHORS file, npm will be processed line by line by default in Name (url) format, mailbox and url are optional. Lines that begin with a # sign and a space are ignored.
Name
The most important fields in package.json are the name and version fields. They are all necessary, and if they don't, they can't install. The identity formed by name and version is unique in the hypothesis. Changing the package should also change the version.
Name is the name of this thing. Note:
Don't put node or js in your name. Because you wrote package.json, it is assumed to be js, but you can specify an engine with the "engine" field (see later).
This name will be used as part of the URL, as an argument on the command line, or as the name of a folder. Any non-url-safe character cannot be used.
This name may be passed into require () as an argument, so it should be short, but it should also be clear.
Before you fall in love with your name, you may want to go to npm registry to see if the name is already in use. Http://registry.npmjs.org/
Version
Version must be parsed by node-semver, which is packaged in npm dependencies. (you can execute npm install semver if you want to use it yourself.)
For available numbers or ranges, see semver (7).
Description
Put introduction, string, easy to search in npm search
Keywords
Keywords, arrays, strings, easy to search in npm search
Bugs
The url and / or email address of your project submission question
{"url": "http://github.com/owner/project/issues"," email ":" project@hostname.com "}
License
You should specify a license to let people know the rights and restrictions to use.
The easiest way is that if you use a general license like BSD or MIT, you only need to specify the name of a license, like this:
{"license": "BSD"}
If you have more complex license conditions, or if you want to provide more details, you can do this:
"licenses": [{"type": "MyLicense", "url": "http://github.com/owner/project/path/to/license"}]
Repository
Specify where your code is stored. This is helpful to those who want to contribute. If the git warehouse is on github, then the npm docs command can find you.
Do this:
"repository": {"type": "git", "url": "http://github.com/isaacs/npm.git"}" repository ": {" type ":" svn "," url ":" http://v8.googlecode.com/svn/trunk/"} "
URL should be a public (even read-only) url that can be processed directly by an unmodified version control program. Should not be a html project page. Because it's for computers.
Scripts
"scripts" is a hash object made up of script commands that are executed during the different lifecycles of the package. Key is a lifecycle event, and value is the command to run.
Config
The "config" hash can be used to configure cross-version parameters for use in package scripts. In an example, if a package has the following configuration:
{"name": "foo", "config": {"port": "8080"}}
Then there is a "start" command that references the npm_package_config_port environment variable, which the user can override through npm config set foo:port 8001.
Dependencies
A dependency is an hash that specifies a version range for a set of package names. This version range is a string separated by one or more spaces. Dependencies can also be tarball or git URL.
Please do not put testing or transitional dependencies in dependencieshash. See devDependencies below
See semver (7) for details.
Version must be completely consistent with version
> version must be larger than version
> = version ditto
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.