当前位置:网站首页>NPM详解
NPM详解
2022-07-25 09:25:00 【Zero摄氏度】
NPM详解
一、NPM包管理器
- 简介
- 官方网站:https://www.npmjs.com/
- NPM全称 Node Packager ,是全球最大的模块生态系统,里面所有的模块都是开源免费的,也是Node.js的包管理器,相当于前端的Maven
- 在安装nodejs时已经配置好了
- 作用
- 快速构建nodejs工程
- 快速安装和依赖第三方模块,比如npm install redis等等
创建nodejs工程
快速构建nodejs工程
- npm init
- 得到package.json 文件内容如下
{
“name”: “npmpro”, //工程名
“version”: “1.0.1”, //版本
“description”: “我是一个node工程”, //描述
“main”: “index.js”, //入口js
“scripts”: { //运行脚本
“test”: “echo “Error: no test specified” && exit 1”
},
“keywords”: [
“node”
],
“author”: “xqh”, //开发者
“license”: “ISC” //授权协议
}
类似于:pom.xml 文件作用管理依赖
- 得到package.json 文件内容如下
- npm包管理器安装模块
- 快速构建nodejs工程
npm init -y 会跳过中间输入的过程,直接创建一个
{
"name": "nodenpm",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
- 快速安装依赖第三方模块
npm install xxxx 或者 npm i xxx模块名
安装好后,会自动生成一个node_modules 的文件,安装好的模块就在那里面
使用
//导入模块
const redis = require("redis");
//导入模块
const mysql = require("mysql");
- 如果安装很慢,用阿里的镜像
npm install -g cnpm --registry=http://registry.npm.taobao.org 阿里的仓库,先下载好仓库
cnpm install jquery 通过阿里仓库来下载,就是把npm变成了cnpm
- 如何运行
node xxx.js 运行过程.js可以省去 ,终止命令行:CTRL+c
- 下载多个
npm mysql redis (如果需要指定版本号,用@去指定版本号)
- 下载好的模块会放在node_modules,还会记录在package.json这个文件中。类似于maven中的pom.xml一个意义
- package.json记录的依赖模块
- 通过npm install 可以直接把package.json所依赖的模块全部自动下载下来
- 这样可以避免重复下载模块,很方便去集成第三模块
- 如何卸载NPM包管理器
- npm unstall vue 卸载vue模块
二、小结
- 快速构建node工程
- 快速安装模块(放在module中,会被记录在package.json中,相当于pom.xml)
- 使用模块
- 卸载模块
边栏推荐
- 概率论与数理统计 3 Discrete Random Variables and Probability Distributions(离散随机变量与概率分布) (下篇)
- Temperature, humidity and light intensity acquisition based on smart cloud platform
- ARMV8体系结构简介
- T5论文总结
- Mlx90640 infrared thermal imager temperature measurement module development instructions
- ARMV8 datasheet学习
- 小程序企业发放红包功能
- ECO简介
- ESP32定时中断实现单、双击、长按等功能的按键状态机Arduino代码
- SystemVerilog语法
猜你喜欢

Coredata storage to do list

看一个双非二本(0实习)大三学生如何拿到阿里、腾讯的offer

【深度学习模型部署】使用TensorFlow Serving + Tornado部署深度学习模型

NLM5系列无线振弦传感采集仪的工作模式及休眠模式下状态

CCF 201509-3 模板生成系统

First knowledge of opencv4.x --- box filtering

Temperature, humidity and light intensity acquisition based on smart cloud platform

AMD EPYC 9664旗舰规格曝光:96核192线程 480MB缓存 3.8GHz频率

小程序调起微信支付

ARM预备知识
随机推荐
OC -- Inheritance and polymorphic and pointer
Mlx90640 infrared thermal imager temperature measurement module development notes (I)
framework打包合并脚本
腾讯云之错误[100007] this env is not enable anonymous login
CCF 201503-4 网络延时
ROS分布式操作--launch文件启动多个机器上的节点
OC -- packaging class and processing object
入住阿里云MQTT物联网平台
LoRA转4G及网关中继器工作原理
ARMv8通用定时器简介
T5 paper summary
LOAM 融合 IMU 细节之 TransformToEnd 函数
【近万字干货】别让你的简历配不上你的才华——手把手教你制作最适合你的简历
关于MLOps中的数据工程,你一定要知道的.......
Mlx90640 infrared thermal imager temperature measurement module development notes (V)
Yolov5 realizes target detection of small data sets -- kolektor defect data set
Exciting method and voltage of vibrating wire sensor by hand-held vibrating wire acquisition instrument
First knowledge of opencv4.x --- box filtering
Visualization of sensor data based on raspberry pie 4B
nodejs链接mysql报错:ER_NOT_SUPPORTED_AUTH_MODEError: ER_NOT_SUPPORTED_AUTH_MODE