版权声明
- 本文原创作者:谷哥的小弟
- 作者博客地址:http://blog.csdn.net/lfdfhl
下载Node.js
请下载Node.js并保存至本地,官方网址:https://nodejs.org/zh-cn/

在此,选择windows系统64位的16.13.1版本进行下载。
下载后解压zip压缩包。
创建全局模块路径和缓存路径
node package mangager简称npm,它常被称为nodejs包管理工具。通过npm命令可以统一管理前端所需依赖。从依赖管理的角度来讲,npm非常类似于Maven。
当我们执行npm时默认将配置文件下载到C盘,其默认路径为:C:\Users\用户名\AppData\Roaming\npm。为减少对C盘系统盘的开销,建议将全局模块和缓存保存至其它位置。
步骤如下:
- 1、在D盘下创建nodejsrepository文件夹
- 2、在nodejsrepository文件夹下创建node_cache文件夹
- 3、在nodejsrepository文件夹下创建node_global文件夹

配置Node.js
在此,介绍Node.js的相关配置。
配置NODE_HOME
变量NODE_HOME的值为Node.js解压后的文件夹所在路径。
配置Path
请在Path尾部追加以下配置:
html
;%NODE_HOME%;D:\nodejsrepository;D:\nodejsrepository\node_global

配置全局模块路径和缓存路径
html
npm config set cache "D:\nodejsrepository\node_cache"
html
npm config set prefix "D:\nodejsrepository\node_global"

配置镜像
为了提升依赖效率,为nodejs配置国内的镜像,命令如下:
html
npm config set registry https://registry.npm.taobao.org
查看镜像,命令如下:
html
npm config get registry

检查
安装完毕之后使用以下三个命令查看版本信息以确认是否安装成功。
html
node -v
html
npm -v
html
npm config ls

总结
总体而言,Node.js的安装和配置过程是比较简单的。在此过程中,请注意细节问题;避免由于粗心大意带来的错误。