npm 学习

npm 的使用

命令概览

zengwe$ npm --help

Usage: npm <command>

where <command> is one of:
    access, adduser, audit, bin, bugs, c, cache, ci, cit,
    completion, config, create, ddp, dedupe, deprecate,
    dist-tag, docs, doctor, edit, explore, get, help,
    help-search, hook, i, init, install, install-test, it, link,
    list, ln, login, logout, ls, outdated, owner, pack, ping,
    prefix, profile, prune, publish, rb, rebuild, repo, restart,
    root, run, run-script, s, se, search, set, shrinkwrap, star,
    stars, start, stop, t, team, test, token, tst, un,
    uninstall, unpublish, unstar, up, update, v, version, view,
    whoami

npm <command> -h  quick help on <command>
npm -l            display full usage info
npm help <term>   search for help on <term>
npm help npm      involved overview

Specify configs in the ini-formatted file:
    **\.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config

npm@6.4.1 **\nodejs\node_modules\npm

项目初始化

zengwe$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help json` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
package name: (temp)
version: (1.0.0)
description:
entry point: (index.js)
test command:
git repository:
keywords:
author:
license: (ISC)
About to write to **\temp\package.json:

{
  "name": "temp",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}


Is this OK? (yes) yes

生成package.json文件

安装包

已有的项目

zengwe$ npm install

安装package.json中的devDependencies和dependencies包

新增的包

zengwe$ npm install request

会在dependencies添加上新安装的包

开发时用的包(非打包的包)

zengwe$ npm install --save-dev request

会在devDependencies添加上新安装的包

安装指定版本的包

zengwe$ npm install request@1.0.0

安装request版本为1.0.0

zengwe$ npm install request^1.0.0

安装版本> 1.0.0即可

全局安装

zengwe$ npm install -g angular-cli

更新

zengwe$ npm update -g angular-cli
zengwe$ npm update request

卸载

zengwe$ npm uninstall -g angular-cli
zengwe$ npm uninstall -g request 

使用node_modules中的命令

比如我在网上clone了一个angular的项目启动项目必须用ng serve,但是我并未安装angular-cli,
解决办法在package.json的scripts中添加’ng serve’
缺点不灵活
可以在项目目录下使用

zengwe$ npx ng serve --port 4201

未完……

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值