nodejs zip安装,配置

本文介绍如何配置npm全局安装位置及缓存路径,并利用淘宝镜像加速npm包的下载。此外,还提供了针对特定资源如node-sass、phantomjs和electron的镜像源配置方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

将文件解压到要安装的位置,并新建两个目录
node-global :npm全局安装位置
node-cache:npm 缓存路径

配置环境变量,path后  在命令行中输入如下命令测试
node -v
npm -v

那么node-global :npm全局安装位置,node-cache:npm 缓存路径 又是怎么与npm发生关系呢?
通过如下命令进行配置:
npm config set prefix "C:\ProgramUser\node-v12.18.3-win-x64\node-global"
npm config set cache "C:\ProgramUser\node-v12.18.3-win-x64\node-cache"

执行npm命令进行测试:npm install webpack -g
执行npm install -g npm 升级最新版本npm
会发现node-global下node_modules中多了webpack 文件夹

设置淘宝镜像
npm config set registry " https://registry.npm.taobao.org " 
更改npm的config的registry 为淘宝镜像,然后再使用npm的时候,就是从淘宝镜像拉取数据了。
在更新node-sass中,有时候也会出现资源下载不了的问题,通常是git上的资源下载不了,这时候,可以更改node-sass的资源路径为淘宝的 
npm config set sass_binary_site=https://npm.taobao.org/mirrors/node-sass/ 
phantomjs的源 
npm config set phantomjs_cdnurl=https://npm.taobao.org/mirrors/phantomjs/ 
electron源 
npm config set electron_mirror=https://npm.taobao.org/mirrors/electron/

 

【用于解决 failed Error: not found: python2 node-sass】 报错信息如下: ``` npm WARN prefer global node-gyp@3.6.0 should be installed with -g > node-sass@4.5.2 install E:\workspace_vscode\ww\node_modules\node-sass > node scripts/install.js Downloading binary from https://github.com/sass/node-sass/releases/download/v4.5 .2/win32-x64-48_binding.node Cannot download "https://github.com/sass/node-sass/releases/download/v4.5.2/win3 2-x64-48_binding.node": connect ETIMEDOUT 54.231.72.83:443 Timed out whilst downloading the prebuilt binary Hint: If github.com is not accessible in your location try setting a proxy via HTTP_PROXY, e.g. export HTTP_PROXY=http://example.com:1234 or configure npm proxy via npm config set proxy http://example.com:8080 > node-sass@4.5.2 postinstall E:\workspace_vscode\ww\node_modules\node-sass > node scripts/build.js gyp verb check python checking for Python executable "python2" in the PATH gyp verb `which` failed Error: not found: python2 gyp verb `which` failed at getNotFoundError ``` 这个问题有两个解决方案 1. 按照提示需要 python2 环境,安装python2环境确实可以解决, 网上好多这种(管理员身份执行)。但是当你本来就有python环境时,环境变量不能自动替换,整起来就很麻烦。 ``` npm install --global --production windows-build-tools ``` 2. 第二种解决方案 ,看另一句报错,资源被墙。 ``` Downloading binary from https://github.com/sass/node-sass/releases/download/v4.5.2/win32-x64-48_binding.node Cannot download "https://github.com/sass/node-sass/releases/download/v4.5.2/win32-x64-48_binding.node": ``` 下载此资源即可。下载后需要设置变量路径,防止它再次去下载。 可以设置环境变量 直接右键我的电脑--》属性--》高级系统设置--》环境变量--》添加 或者执行 ``` set SASS_BINARY_PATH=D:\nodejs\tools\node-sass\win32-x64-46_binding.node ``` 再次执行 npm install 成功
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值