我的node环境
Node 环境
nvm
便于管理维护 node 版本
安装/更新
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash
验证安装(安装完需要重启终端)
command -v nvm
常用命令(非 win 版本)
下载最新版本
nvm install node
下载指定版本
nvm install
显示所有版本
nvm ls-remote
显示所有 LTS 版本
nvm ls-remote --lts
切换版本
nvm use node
查询安装位置
nvm which 8.16.0
nrm
npm 的镜像源管理工具,便于切换不同的 npm
安装
npm install -g nrm
npm install -g nrm --registry=https://registry.npm.taobao.org
常用命令
显示所有源
nrm ls
当前使用源
nrm current
切换
nrm use taobao
增加
nrm add learnzs http://localhost:4873
删除
nrm del learnzs
cnpm
淘宝 npm 镜像
安装
npm install -g cnpm --registry=https://registry.npm.taobao.org
使用
所有 npm 命令切换为 cnpm,例:
cnpm instsll [name]
注: 不能使用publish
verdaccio
npm 私有仓库
安装
npm install --global verdaccio
启动
verdaccio
verdaccio -c /verdaccio/config.yaml
使用
npm install lodash --registry http://localhost:4873
npm install nodemon -g --registry http://localhost:4873
或使用 nrm 增加源
nrm add local http://localhost:4873
npm install lodash
查看
http://localhost:4873/-/web/detail/nodemon
配置文件
/verdaccio/config.yaml
#
# This is the default config file. It allows all users to do anything,
# so don't use it on production systems.
#
# Look here for more config file examples:
# https://github.com/verdaccio/verdaccio/tree/master/conf
#
# path to a directory with all packages
storage: /Users/zhaosai/Workspaces/verdaccio/storage
# path to a directory with plugins to include
plugins: /Users/zhaosai/Workspaces/verdaccio/plugins
web:
title: LearnZS - npm仓库
logo: /Users/zhaosai/Workspaces/verdaccio/logo.png
primary_color: '#5290CB'
# comment out to disable gravatar support
gravatar: true
# by default packages are ordercer ascendant (asc|desc)
sort_packages: asc
# convert your UI to the dark side
# darkMode: true
# translate your registry, api i18n not available yet
i18n:
# list of the available translations https://github.com/verdaccio/ui/tree/master/i18n/translations
web: zh-CN
auth:
htpasswd:
file: /Users/zhaosai/Workspaces/verdaccio/htpasswd
# Maximum amount of users allowed to register, defaults to "+inf".
# You can set this to -1 to disable registration.
# max_users: 1000
# a list of other known repositories we can talk to
#
uplinks:
npmjs:
url: https://registry.npm.taobao.org/
packages:
'@*/*':
# scoped packages
access: $all
publish: $authenticated
unpublish: $authenticated
proxy: npmjs
'**':
# allow all users (including non-authenticated users) to read and
# publish all packages
#
# you can specify usernames/groupnames (depending on your auth plugin)
# and three keywords: "$all", "$anonymous", "$authenticated"
access: $all
# allow all known users to publish/publish packages
# (anyone can register by default, remember?)
publish: $authenticated
unpublish: $authenticated
# if package is not available locally, proxy requests to 'npmjs' registry
proxy: npmjs
# You can specify HTTP/1.1 server keep alive timeout in seconds for incoming connections.
# A value of 0 makes the http server behave similarly to Node.js versions prior to 8.0.0, which did not have a keep-alive timeout.
# WORKAROUND: Through given configuration you can workaround following issue https://github.com/verdaccio/verdaccio/issues/301. Set to 0 in case 60 is not enough.
server:
keepAliveTimeout: 60
middlewares:
audit:
enabled: true
# log settings
logs:
- { type: stdout, format: pretty, level: http }
#- {type: file, path: verdaccio.log, level: info}
#experiments:
# # support for npm token command
# token: false
listen: 0.0.0.0:4873
默认npm包
/verdaccio/storage/.verdaccio-db.json
{
"list": [
"axios",
"moment",
"vuew-filters",
"@vue/cli",
"@dcloudio/uni-ui",
"lodash",
"iview",
"nrm",
"verdaccio",
"cloc",
"pm2",
"typescript",
"express-generator",
"gitbook-cli",
"less",
"@quasar/cli",
"nativefier",
"spy-debugger",
"wepy-cli",
"cnpm"
],
"secret": "d6b54706025b84daef58c8dce5fb0d62472f3c7a647d8b0cefd43f200aa798da"
}
web 端
可以在浏览器中直接访问http://localhost:4873
配置
pm2
node 进程管理
安装
npm install pm2 -g
更新
# Install latest PM2 version
npm install pm2@latest -g
# Save process list, exit old PM2 & restore all processes
pm2 update
非 node 方式
wget -qO- https://getpm2.com/install.sh | bash
常用命令
启动程序
pm2 start app.js
查看所有进程
pm2 list
关闭
pm2 stop <app_name|namespace|id|'all'|json_conf>
重启
pm2 restart <app_name|namespace|id|'all'|json_conf>
删除
pm2 delete <app_name|namespace|id|'all'|json_conf>
控制台
pm2 monit
pm2 dash
详情
pm2 describe <id|app_name>
pm2 info <id|app_name>
查看日志
pm2 logs <id|app_name>
开机启动
pm2 save
pm2 startup
取消开机启动
pm2 stsyemd
pm2 unstartup
cloc
代码统计工具
安装/更新
npm install -g cloc
验证安装
cloc
常用命令
下载最新版本(重新按安装即可)
npm install -g cloc
whistle
基于Node.js的跨平台Web代理及调试工具
安装/更新
npm install -g whistle
验证安装
w2 -h
常用命令
下载最新版本(重新安装或npm更新即可)
npm upgrade whistle
帮助文档
w2 -h
启动
w2 start
w2 start -p 8888 // 设置端口
关闭
w2 stop
重启
w2 restart
其它代理工具
https://api.getfiddler.com/win/latest
名称
介绍
安装/更新
验证安装
常用命令
下载最新版本