本文简要讲述node的安装和使用
安装
centos端安装
可以随意替换版本。例如10.23.0
# 卸载系统可能自带的低版本node
yum remove nodejs npm -y
# 下载、解压
wget http://mirrors.ustc.edu.cn/node/v14.17.4/node-v14.17.4-linux-x64.tar.gz
tar -zxvf node-v14.17.4-linux-x64.tar.gz
rm node-v14.17.4-linux-x64.tar.gz
mv node-v14.17.4-linux-x64 /usr/local/node
# 配置环境变量
sduo vim /etc/profile
#set for nodejs
export NODE_HOME=/usr/local/node
export PATH=$NODE_HOME/bin:$PATH
EOF
source /etc/profile
windows端
mac
brew install node
包管理工具
npm
尽量使用npm,不容易出现问题,尽量不要使用淘宝镜像,会出现莫名的问题。嫌慢就开全局代理
# 安装示例
npm i webpack # 在module文件中安装
npm i webpack -S # 常用,添加到package
npm i webpack -g # 全局
# 卸载
npm un webpack -g
# 更新
npm update webpack -g
npm i npm@latest -g # 更新npm自己到最新
# npm版本
npm -v
yarn
tyarn 为淘宝源,可以直接使用。
npm i yarn tyarn -g
tyarn -v
使用
# 初始化项目
yarn
# 安装
yarn add react
# 卸载
yarn remove react
# 安装到dev
yarn add react --dev
# 更新项目包
yarn upgrade
# 全局安装
yarn global add umi
# yarn升级自己
yarn self-update # 这个命令用来升级Yarn到最新的版本。
yarn self-update [tag] # 命令将会安装指定版本的Yarn。
yarn全局安装的工具默认是没有加入到环境变量的。
# 获取环境变量
yarn global bin
# mac 系统:
$ sudo vi ~/.bashrc
# 在 .bashrc 中添加下面一行:
export PATH="$PATH:`yarn global bin`"
# windows系统:
# 获取 global bin 的路径
$ yarn global bin
C:\Users\Administrator\AppData\Local\Yarn\bin
# 复制上面的 global bin 的路径,添加到系统环境变量 PATH。
其他
serve
快速搭建一个本地服务器,够方便。
安装: yarn global add serve
使用:
$ serve dist/
INFO: Accepting connections at http://localhost:5000
now
把本地web项目推送到远程服务器,让更多人可以访问。
因为发布的代码是开源的,所以我只当做临时使用,更详细的教程请参考这里
准备工作:
- 安装:
yarn global add now
- 注册:https://zeit.co/dashboard
- 本地登录一下:
now login your@gamil.com
,然后登录你的邮箱验证就可以了。
正常使用:
$ now ./dist/
> Deploying D:\我的坚果云\code\web\ant-design\myapp\dist under tianyun
> Using project dist
> WARN! This is the first deployment in the dist project. It will be promoted to production.
https://dist-gxcomv0zz.now.sh- Finalizing...
> Ready! Deployed to https://dist.tianyun.now.sh [in clipboard] [34s]
pm2
后台管理并运行node项目。
安装:yarn global add pm2
使用:
待完善
问题
全局安装后找不到命令
1、查看全局目录
npm root -g
2、 添加到环境变量