npm

info

1
2
3
4
5
6
7
8
npm -v //查看版本
sudo npm install npm@latest -g 更新
npm login
npm whoami




install local packages

1
2
3
npm install npm@next -g
npm install <package_name>
require('qr-image');

package.json

必要参数

  • name
  • version

create

1
npm init

modify

1
2
3
npm set init.author.email "wombat@npmjs.com"
npm set init.author.name "ag_dubs"
npm set init.license "MIT"

.npm-init.js

1
2
3
4
5
6
~/.npm-init.js

module.exports = {
customField: 'Custom Field',
otherCustomField: 'This field is really cool'
}

Running npm init with this file in your home directory would output a package.json that included these lines:

1
2
3
4
{
customField: 'Custom Field',
otherCustomField: 'This field is really cool'
}

-

dependencies

These packages are required by your application in production.

1
npm install <package_name> [--save-prod]

-

devDependencies

These packages are only needed for development and testing.

1
npm install <package_name> --save-dev

update local package

1
run npm update in the same directory as the package.json file of the application that you want to update

Uninstall Local Packages

1
2
npm uninstall lodash
npm uninstall --save lodash

Global Packages

1
2
3
4
5
6
7
8
9
npm install -g <package>
npm update -g <package>
// 查看需要升级的全局包
npm outdated -g --depth=0
//更新所有包
npm update -g

npm install npm@latest -g
npm uninstall -g <package>

create nodejs model

  • creating a package.json file

Publish & Update a Package

1
2
npm publish
npm version patch|minor|major

Update the Read Me File

before Update the readme file , must update version ,it mean your version is a Snapshot

文章链接 https://fangzongzhou.github.io/2018/07/05/计算机/技术栈/前端/npm/