「一劳永逸」brew、node、nvm、npm、yrm、yarn、http-server、查看并停掉占用进程

1,469 阅读2分钟

以下内容都是以Mac使用习惯为例,请大家见谅~~~

brew

具体安装、卸载、切换源、加速 juejin.cn/post/693348…

node

// 一台空白的电脑,首先是用brew 安装 nvm, 后面再用nvm来安装node
// 当电脑没有安装brew时可以尝试
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash

// 安装 nvm node版本管理工具 
brew install nvm

nvm install stable ## 安装最新稳定版 node,当前是node v9.5.0 (npm v5.6.0)

nvm install <version> ## 安装指定版本,可模糊安装,如:安装v4.4.0,既可nvm install v4.4.0,又可nvm install 4.4

nvm uninstall <version> ## 删除已安装的指定版本,语法与install类似

nvm use <version> ## 切换使用指定的版本node

nvm ls ## 列出所有安装的版本

nvm ls-remote ## 列出所有远程服务器的版本(官方node version list)

nvm current ## 显示当前的版本

nvm alias <name> <version> ## 给不同的版本号添加别名

nvm unalias <name> ## 删除已定义的别名

nvm reinstall-packages <version> ## 在当前版本 node 环境下,重新全局安装指定版本号的 npm 包

nvm alias default <version> ## 设置默认的node版本

npm

检查npm是否登录
npm whoami

登录
npm login

查看当前 npm 的配置信息
npm config list

切换到 淘宝 源
npx nrm use taobao

切换回 npm 源
npx nrm use npm   

//.npmrc文件内容,地址可设置为内网源
registry="https://registry.npm.taobao.org/"

// 获取本地镜像源 
npm get registry 

npm config set registry http://registry.npm.taobao.org/

yarn config set registry http://registry.npm.taobao.org/

注: npx 这个执行器会先在本地找一下有没有nrm,没有下载一个,然后再进行源切换

yrm——npm源管理器

安装
npm install -g yrm

列出可选源
yrm ls

  npm ---- https://registry.npmjs.org/
  cnpm --- http://r.cnpmjs.org/
* taobao - https://registry.npm.taobao.org/
  nj ----- https://registry.nodejitsu.com/
  rednpm - http://registry.mirror.cqupt.edu.cn/
  npmMirror  https://skimdb.npmjs.com/registry/
  edunpm - http://registry.enpmjs.org/
  yarn --- https://registry.yarnpkg.com

源切换
yrm use taobao   (使用这个会同时将npm、yarn的源切到taobao)

   YARN Registry has been set to: https://registry.npm.taobao.org/

源速度测试
yrm test

  npm ---- 784ms
  cnpm --- 290ms
* taobao - 297ms
  nj ----- Fetch Error
  rednpm - Fetch Error
  npmMirror  1353ms
  edunpm - Fetch Error
  yarn --- Fetch Error

yarn

//查看当前源
yarn config get registry
//设置淘宝源或内网源
yarn config set registry https://registry.npm.taobao.org --global
//恢复源
yarn config set registry https://registry.yarnpkg.com --global

http-server

可以很方便的起一个http服务

npm i -g http-server
http-server -p 端口

查看、杀掉占用进程

打开mac终端,或者idea的终端,输入: lsof -i:端口号(我的是8020,那么输入如下命令)
lsof -i:8020

输入 lsof -i:8020 后回车

bogon:it399_springboot chenshouyin$ lsof -i:8020\
COMMAND  PID        USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME\
java    1472 chenshouyin  120u  IPv6 0x71c9463ce2ac6f49      0t0  TCP *:intu-ec-svcdisc (LISTEN)\
bogon:it399_springboot chenshouyin

可以看到我的端口对应的进程id是1472,那么kill这个进程即可

mac下关闭进程

kill 进程id,上面我的进程id是1472,那么直接输入如下命令即可

kill 1472

kill -9 1472

命令行启动vscode

  1. 打开vscode,MAC用户按住command+shift+p,windows用户按住control+shift+p,此时会弹出一个命令窗口

截屏2022-04-15 下午1.51.18.png

  1. 点击在path中安装“code”命令

  2. code ./就可以调起vscode编辑器