Node(npm使用介绍)

NPM使用介绍

NPM是随同NodeJS一起安装的包管理工具,使用场景有:

  • 允许用户从NPM服务器下载别人编写的第三方包到本地使用
  • 允许用户从NPM服务器下载并安装别人编写的命令行程序到本地使用。
  • 允许用户将自己编写的包或命令行程序上传到NPM服务器供别人使用。

项目初始化

'npm init'

'npm init -y'

 

使用淘宝镜像的命令

npm install -g cnpm --registry=https://registry.npmmirror.com

使用npm安装模块

npm 安装 Node.js 模块语法格式如下:

$ npm install <Module Name>

使用 npm 命令安装常用的 Node.js web框架模块 nodemon:

$ npm install nodemon

全局安装与本地安装

'npm install'
'npm install 包名 --save' --save简写-S
'npm install 包名 -g'  -g全局

 

npm install nodemon          # 本地安装
npm install nodemon -g   # 全局安装

 卸载模块

'npm uninstall 包名 -g'  删除  不加-g删除当前项目  加-g是全局

更新模块

$ npm update nodemon

 

版本模块

'npm install 包名@版本号 --save/-g'  没有版本号装的是最新的

查看版本号

nodemon -V

 

Package.json 属性

  • name - 包名
  • version - 包的版本号
  • description - 包的描述
  • homepage - 包的官网URL
  • author - 包的作者姓名
  • contributors - 包的其他贡献者姓名
  • repository - 包代码存放地方的类型
  • keywords - 关键字

 

posted @ 2021-11-24 18:53  .Nice  阅读(139)  评论(0)    收藏  举报