03-NPM详解
最后更新于
这有帮助吗?
最后更新于
这有帮助吗?
这有帮助吗?
#建立一个空文件夹,在命令提示符进入该文件夹 执行命令初始化
npm init
#按照提示输入相关信息,如果是用默认值则直接回车即可。
#name: 项目名称
#version: 项目版本号
#description: 项目描述
#keywords: {Array}关键词,便于用户搜索到我们的项目
#最后会生成package.json文件,这个是包的配置文件,相当于maven的pom.xml
#我们之后也可以根据需要进行修改。{
"name": "npmpro", // 工程名
"version": "1.0.0", // 版本号
"description": "我是一个nodejs工程", // 描述
"main": "index.js", // 入口js文件
"scripts": { // 运行脚本
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "learn", // 开发者名称
"license": "ISC" // 授权协议
}npm init -ynpm install -g cnpm --registry=https://registry.npm.taobao.orgnpm install 模块名npm i 模块名npm install #根据package.json中的配置下载依赖,初始化项目#如果安装时想指定特定的版本
npm install jquery@2.1.x#devDependencies节点:开发时的依赖包,项目打包到生产环境的时候不包含的依赖
#使用 -D参数将依赖添加到devDependencies节点
npm install --save-dev eslint
#或
npm install -D eslintnpm install -g webpackconst mysql = require("mysql")const redis = require('redis')
const client = redis.createClient(6379, '127.0.0.1');
client.on("error", function(error){
console.error(error)
});
client.set("key","value",redis.print);
client.get("key",redis.print);#经过下面的配置,以后所有的 npm install 都会经过淘宝的镜像地址下载
npm config set registry https://registry.npm.taobao.org
#查看npm配置信息
npm config list#更新包(更新到最新版本)
npm update 包名
#全局更新
npm update -g 包名
#卸载包
npm uninstall 包名
#全局卸载
npm uninstall -g 包名