真的你只需要看官方文档就好了,https://nodejs.org/zh-cn
Node.js 搞Web服务就是很方便。
搞懂EventLoop 事件循环很重要的。
安装到当前项目,写入 package.json
npm install express
# 简写
npm i express安装后 package.json
{
"dependencies": {
"express": "^5.1.0"
}
}npm install -D typescript
# 或
npm i --save-dev typescript
{
"devDependencies": {
"typescript": "^5.9.0"
}
}npm install express@5.1.0
# 或
npm install express@latestnpm uninstall express
# 或
npm remove express执行后:
node_modulespackage-lock.json 中记录package.json 中对应项查看过期包
npm outdated
# 更新
npm update
# 升级到最新版
npm install express@latestnpm install
# 或
npm ci| 命令 | 用途 |
|---|---|
| npm install | 普通开发 |
| npm ci | CI/CD、严格按 lock 文件安装 |
npm config get registry
https://registry.npmjs.org/
# 国内镜像
npm config set registry https://registry.npmmirror.com
# 验证
npm config get registry
https://registry.npmmirror.com
# 恢复官方
npm config set registry https://registry.npmjs.orgnpm config list
# 或
npm config ls -l查看缓存目录
npm config get cache
# macos ~/.npm
# linux ~/.npm
# windows C:\Users\<用户名>\AppData\Local\npm-cache清理缓存
npm cache clean --force
# 查看缓存
npm cache verify查看
npm root -g
# 例如
/opt/homebrew/lib/node_modules
# 查看全局可执行程序目录
npm bin -g
# 常见 /opt/homebrew/bin