npm常用命令及实战

npm init会引导你创建一个package.json文件,包括名称、版本、作者这些信息等
npm install <name>

安装nodejs的依赖包

例如npm install express 就会默认安装express的最新版本

也可以通过在后面加版本号的方式安装指定版本,如npm install express@3.0.6

npm install <name> -g将包安装到全局环境中
npm install <name> --save

安装的同时,将信息写入package.json中

任选其一即可:[--save|--save-dev|--save-optional]

 

--save: Package will appear in your dependencies.

--save-dev: Package will appear in your devDependencies.

--save-optional: Package will appear in your optionalDependencies.

npm remove <name>移除安装包
npm update <name>更新安装包
npm ls列出当前安装的了所有包
npm root查看当前包的安装路径

npm root -g  查看全局的包的安装路径

npm help  帮助,如果要单独查看install命令的帮助,可以使用的npm help install

 

实战:

1、我们先创建一个文件夹:test(测试使用)

2、进入test目录  npm init 

 

Press ^C at any time to quit.
name: (test) test
version: (0.0.0) 0.0.1
description: this is for testting
entry point: (index.js) index.js
test command: node index.js
git repository:
keywords:
author:
license: (ISC)
About to write to D:\happy\node\test\package.json:

{
  "name": "test",
  "version": "0.0.1",
  "description": "this is for testting",
  "main": "index.js",
  "scripts": {
    "test": "node index.js"
  },
  "author": "",
  "license": "ISC"
}

 

 

3、目录下会自动生成一个:package.json

4、安装自己所需的依赖包:npm install <name> --save

"dependencies": {
    "mysql": "^2.5.2"
  }

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值