npm

npm

 

npm 是世界上最大的开放源代码的生态系统。我们可以通过 npm 下载各种各样的包, 这些源代码(包)我们可以在 https://www.npmjs.com 找到。

 

npm 是随同 NodeJS 一起安装的包管理工具,能解决 NodeJS 代码部署上的很多问题

 

作用:帮助你安装模块(包),自动安装依赖,管理包(增,删,更新,项目所有包),类似yarn 

安装到全局坏境

安装到电脑系统环境下

使用时在任何位置都可以使用

被全局安装的通常是:命令行工具 脚手架

npm i 包名 -g                  安装

npm uninstall  包名 - g   卸载

- g  全局 global 

安装到项目环境

只能在当前目录使用,需要使用npm代运行

npm init 

初始化npm管理文件package.json

package-lock.json 文件用来固化依赖

{
"name": "npm", //项目名称
"version": "0.0.1", //版本
"description": "test and play", //描述
"main": "index.js", //入口文件
"dependencies": { //项目依赖(运行式依赖)  上线也要用
"jquery": "^3.2.1"
},
"devDependencies": { //开发依赖 上线就不用 (只是开发用到)
"animate.css": "^3.5.2"
},
"scripts": { //命令行
"test": "命令行",
},
"repository": { //仓库信息
"type": "git",
"url": "xx"
},
"keywords": [ //关键词
"test",'xx','oo'
],
"author": "kery",
"license": "ISC", //认证
"bugs": {
"url": "xx"//问题提交
},
"homepage": "xx"//首页
}

注:在项目中npm init进行初始化的时候一路敲空格,最后输入y即可,也可以直接输入npm init -y  ,y就是最后面的确定的那个y

项目依赖

只能在当前项目下使用,上线了,也需要这个依赖  --save

// 安装

npm i  包名 -- save  |  -S   

npm install 包名 -S

// 卸载

npm uninstall 包名 --save  | -S

npm uninstall 包名 -S

开发依赖

只能在当前项目下使用 ,上线了,依赖不需要了  --save-dev

  npm install 包名 -save-dev

  npm install 包名 -D

查看包

npm list  列出所有已安装包

npm outdated 版本对比(安装过得包)

npm info 包名 查看当前包概要信息

npm view 包名 versions 查看包历史版本列表

安装所有依赖

npm install   安装package.json里面指定的所有包

选择源

npm install nrm -g   安装选择源的工具包

nrm ls 查看所有源

nrm use 切换源名

安装卡顿时

ctrl + c -> npm uninstall 包名 -> npm cache 清除缓存 -> 换4g网络-> npm install包名

 

posted @ 2020-11-19 21:19  码农小超  阅读(79)  评论(0)    收藏  举报