npm understanding, use and installation
What is npm?
NPM (node package manager), commonly referred to as the package manager node
As the name suggests, his main function is to manage node package;
including: install, uninstall, update, view, search, publishing;
behind npm is based on a database of couchdb, a detailed record of each packet of information, including author, version dependence, authorization information. It's a very important role is: will the developers from the tedious management package (version dependent, etc.) of liberation, more focused on the development functions.
It's official web site is https://npmjs.org/
View version
npm -v
Upgrading an older version of NPM
npm install npm -g
Taobao Mirror
When installing webstorm the network fluctuations installation fails if there is, we can check the input code is correct and then locate
the c drive / user (or user) / AppData / Roaming / npm ( and npm-cache)
installation clearance failed file cnpm documents; without the necessary files can be deleted directly npm / folder npm-cache file and re-install;
if or installation fails, do not give up more than a few installation
npm install -g cnpm --registry=https://registy.npm.taobao.org
Generating JSON configuration file
npm init -y
The above command can be input to generate a configuration file (packsge.json)
"name"//项目名称
"version"//版本
"description"//详细的描述;项目是干什么的
"main"//入口js;当项目首页注入js时;在对应路径中新建index.js文件
"dependencies"//项目依赖
"devDependencies"//开发测试依赖(我这里没有)
"scripts"//命令行,执行脚本("v":"cnpm -v")
"keywords"//关键字
"author"//作者
"description"//详细的描述;项目是干什么的
"license"//版权许可证(默认:ISC)
Installation package
npm install //安装
npm i //安装简写
npm install (包名@0.1.1) //安装包
npm install (包名) -global //全局安装,任意一个项目都可以访问到;
npm i -g //全局安装的简写
npm install (包名) --save //添加到dependencies(项目依赖),项目上线时候需到的包
npm install (包名) -S //添加到dependencies的简写(字母大写)
npm install (包名) --save-dev //添加到devDependencies(开发依赖)
npm install (包名) -D //添加到devDependencies(开发依赖)的简写
//开发代码使用的包,例如测试,验证等使用的模块的包
Update Module
npm update (包名) //这是更新到最新的版本
npm install (包名@版本) //我们一般使用这个来更新
Delete module
npm uninstall (包名) //删除包
npm uninstall (包名) -g //删除全局中的包
npm uninstall (包名) --save或者npm uninstall (包名) -S //删除项目依赖的模块
npm uninstall (包名) --save-dev 或者npm uninstall (包名) -D //删除开发依赖的模块
Execute scripts
npm run //指令
{
"name": "myproject",
"devDependencies": {
"jshint": "latest",
"browserify": "latest",
"mocha": "latest"
},
"scripts": {
"dev": "node server.js",
"lint": "eslint **.js",
"test": "mocha test/"
}
}
You can not use keywords such node
values must be enclosed in double quotes
when used directly RUN dev NPM
lint eslint generally used must be installed when the code format check
test is generally used when the code must be installed tested using mocha