NodeJS zip版安装与配置
程序员文章站
2022-06-15 22:44:28
...
1、Nodejs下载地址:
https://nodejs.org/en/download/
或者直接进入链接:
https://nodejs.org/dist/v12.18.2/node-v12.18.2-win-x64.zip
解压到对应目录。(我的位置是:D:/tools)
2、在解压后的目录中新增两个文件夹
node-global :npm全局安装位置
node-cache:npm 缓存路径
3、环境变量配置
将node.exe 所在的目录添加到path环境变量,这样我们在使用命令行时就可以在任意路径使用node命令了,同时该目录下有一个npm.cmd文件,打开文件其实就i是将我们的npm命令映射到node.exe npm-cli.js,由于存在该映射所以只要把node.exe 所在的目录添加到path环境变量,也可以在任何目录下执行npm install了。
写到这里其实node就算已经装好了。
在命令行中输入如下命令测试
C:\Users\josh>node -v v12.18.2
查看npm版本号
C:\Users\josh>npm -v 6.14.5
4、设置全局环境
C:\Users\josh>npm config set prefix "D:\tools\node-v12.18.2-win-x64\node-global" C:\Users\josh>npm config set cache "D:\tools\node-v12.18.2-win-x64\node-cache"
执行以下代码测试:
C:\Users\josh>npm install webpack -g npm ERR! code ETIMEDOUT npm ERR! errno ETIMEDOUT npm ERR! network request to https://registry.npmjs.org/webpack failed, reason: connect ETIMEDOUT 104.16.17.35:443 npm ERR! network This is a problem related to network connectivity. npm ERR! network In most cases you are behind a proxy or have bad network settings. npm ERR! network npm ERR! network If you are behind a proxy, please make sure that the npm ERR! network 'proxy' config is set properly. See: 'npm help config' npm ERR! A complete log of this run can be found in: npm ERR! D:\tools\node-v12.18.2-win-x64\node-cache\_logs\2020-07-07T03_12_40_659Z-debug.log
可能出现以上错误,原因是国外服务器,比较慢。
设置淘宝镜像:
npm config set registry http://registry.npm.taobao.org/
安装cnpm
C:\Users\josh>npm install -g cnpm --registry=https://registry.npm.taobao.org npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142 D:\tools\node-v12.18.2-win-x64\node-global\cnpm -> D:\tools\node-v12.18.2-win-x64\node-global\node_modules\cnpm\bin\cnpm+ cnpm@6.1.1 added 685 packages from 957 contributors in 37.168s
查看cnpm是否已安装好:
C:\Users\josh>cnpm -v cnpm@6.1.1 (D:\tools\node-v12.18.2-win-x64\node-global\node_modules\cnpm\lib\parse_argv.js) npm@6.14.5 (D:\tools\node-v12.18.2-win-x64\node-global\node_modules\cnpm\node_modules\npm\lib\npm.js) node@12.18.2 (D:\tools\node-v12.18.2-win-x64\node.exe) npminstall@3.27.0 (D:\tools\node-v12.18.2-win-x64\node-global\node_modules\cnpm\node_modules\npminstall\lib\index.js) prefix=D:\tools\node-v12.18.2-win-x64\node-global win32 x64 10.0.17763 registry=https://r.npm.taobao.org
安装webpack
C:\Users\josh>npm install webpack -g npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies. npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2. D:\tools\node-v12.18.2-win-x64\node-global\webpack -> D:\tools\node-v12.18.2-win-x64\node-global\node_modules\webpack\bin\webpack.js npm WARN notsup Unsupported engine for watchpack-chokidar2@2.0.0: wanted: {"node":"<8.10.0"} (current: {"node":"12.18.2","npm":"6.14.5"}) npm WARN notsup Not compatible with your version of node/npm: watchpack-chokidar2@2.0.0 npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules\webpack\node_modules\watchpack-chokidar2\node_modules\fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"}) npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules\webpack\node_modules\fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"}) + webpack@4.43.0 added 343 packages from 200 contributors in 25.754s
上一篇: c++ ini 文件的读写及相关函数