npm指令
测试是否安装 yes/返回版本
npm -v
安装npm
新版的nodejs已经集成了npm,已经安装好了npm
如果使用的旧版本
使用npm install npm -g 即可安装
使用npm安装模块
语法格式npm install <模板名称>
全局安装&本地安装
本地安装和全局安装从输入的命令行来看没什么区别, 区别只在-g
npm install express //本地
npm install express -g //全局
安装出现问题如:
npm err! Error connect ECONNREFUSED 127.0.0.1:8087
解决方法
npm config set proxy null
查看安装信息
npm list -g
查看node_modules(模块文件)下的模块
npm ls
查看某个模块版本
npm lsit 模块名称
卸载模块
npm uninstall 模块名称
更新模块
npm update 模块名称
搜索模块
npm search 模块名称
创建模块
在输入 'npm init' 后
命令行会打印出如下:
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.
See `npm help init` for definitive documentation on these fields
and exactly what they do.
Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.
Press ^C at any time to quit.
package name : 模块名称
version:(1.0.0) 版本号
description: 描述
entry point:(index.js)
test command:make test
git repository:Github地址
keywords:
author:
license:(ISC)
//自动生成地址
About to write to C:\Users\34286\Desktop\Web\Node\package.json:
//预览
{
"name": "demo",
"version": "1.0.0",
"description": "Node.js",
"main": "node.js",
"scripts": {
"test": "make test"
},
"author": "pan",
"license": "ISC",
"dependencies": {
"express": "^4.17.2"
},
"devDependencies": {}
}
//是否创建
Is this OK? (yes)