Windows搭建Nodejs全网最详细

Posted Adorable_Rocy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Windows搭建Nodejs全网最详细相关的知识,希望对你有一定的参考价值。

1.下载镜像【WIN7用户看这里

2.默认安装完毕后,创建node_global&node_cache文件夹

补充:它默认是存储在C:\\Users\\ROOT\\AppData\\Roaming的

3.修改默认环境

npm config set prefix "C:\\Program Files\\nodejs\\node_global"

npm config set cache "C:\\Program Files\\nodejs\\node_cache"

4.环境变量(NODE_PATH)

修改用户变量的npm路径C:\\Program Files\\nodejs\\node_global

5.安装全局文件

 npm install webpack -g 

补充:有的同学可能会报错哈

npm ERR! code EPERM
npm ERR! syscall mkdir
npm ERR! path C:\\Program Files\\nodejs\\node_cache\\_cacache
npm ERR! errno EPERM
npm ERR! FetchError: Invalid response body while trying to fetch https://registry.npmjs.org/webpack: EPERM: operation not permitted, mkdir 'C:\\Program Files\\nodejs\\node_cache\\_cacache'
npm ERR!     at C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\minipass-fetch\\lib\\body.js:162:15
npm ERR!     at async Arborist.[nodeFromEdge] (C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\@npmcli\\arborist\\lib\\arborist\\build-ideal-tree.js:1082:19)
npm ERR!     at async Arborist.[buildDepStep] (C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\@npmcli\\arborist\\lib\\arborist\\build-ideal-tree.js:951:11)
npm ERR!     at async Arborist.buildIdealTree (C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\@npmcli\\arborist\\lib\\arborist\\build-ideal-tree.js:215:7)
npm ERR!     at async Arborist.reify (C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\@npmcli\\arborist\\lib\\arborist\\reify.js:152:5)
npm ERR!     at async Install.exec (C:\\Program Files\\nodejs\\node_modules\\npm\\lib\\commands\\install.js:157:5)
npm ERR!     at async module.exports (C:\\Program Files\\nodejs\\node_modules\\npm\\lib\\cli.js:66:5)
npm ERR!  FetchError: Invalid response body while trying to fetch https://registry.npmjs.org/webpack: EPERM: operation not permitted, mkdir 'C:\\Program Files\\nodejs\\node_cache\\_cacache'
npm ERR!     at C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\minipass-fetch\\lib\\body.js:162:15
npm ERR!     at async Arborist.[nodeFromEdge] (C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\@npmcli\\arborist\\lib\\arborist\\build-ideal-tree.js:1082:19)
npm ERR!     at async Arborist.[buildDepStep] (C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\@npmcli\\arborist\\lib\\arborist\\build-ideal-tree.js:951:11)
npm ERR!     at async Arborist.buildIdealTree (C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\@npmcli\\arborist\\lib\\arborist\\build-ideal-tree.js:215:7)
npm ERR!     at async Arborist.reify (C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\@npmcli\\arborist\\lib\\arborist\\reify.js:152:5)
npm ERR!     at async Install.exec (C:\\Program Files\\nodejs\\node_modules\\npm\\lib\\commands\\install.js:157:5)
npm ERR!     at async module.exports (C:\\Program Files\\nodejs\\node_modules\\npm\\lib\\cli.js:66:5) 
npm ERR!   code: 'EPERM',
npm ERR!   errno: 'EPERM',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: 'C:\\\\Program Files\\\\nodejs\\\\node_cache\\\\_cacache',
npm ERR!   type: 'system',
npm ERR!   requiredBy: '.'
npm ERR! 
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It's possible that the file was already in use (by a text editor or antivirus),
npm ERR! or that you lack permissions to access it.
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in:

是因为当前用户没权限写入文件夹

  • 解决方案一


给一下权限就OK了

  • 解决方案二

写入完成

查看webpack版本

6.设置镜像

npm config get registry # 查看当前镜像库

npm config set registry https://registry.npm.taobao.org --global # 设置全局淘宝镜像

npm config set registry https://registry.npmjs.org/ # 切换回默认地址

npx nrm use taobao  # 切换到淘宝源

npx nrm use npm # 切换到官方

  • 安装cnpm
npm install -g cnpm --registry=https://registry.npmmirror.com

cnpm -v # 查看版本

npm list -g # 查看全局安装的模块

npm list vue # 查看某个模块的版本号

npm install sass-node@x.x.x # 安装提定版本包

npm update sass-node # 更新到最新版的包

npm uninstall jquery # 卸载包

7.执行报错

Error while executing: npm ERR! D:\\Program Files\\Git\\cmd\\git.EXE ls-remote -h -t git://github.com/ad
npm config set registry https://registry.npmmirror.com

# 使用淘宝镜像安装即可
npm install --registry=https://registry.npm.taobao.org

以上是关于Windows搭建Nodejs全网最详细的主要内容,如果未能解决你的问题,请参考以下文章

这可能是全网最详细的python安装教程(windows)

全网最详细的Windows里下载与安装Sublime Text *(图文详解)

可能是全网最详细的python安装教程(windows),小白建议收藏

可能是全网最详细的python安装教程(windows),小白建议收藏

全网最详细的Mac下搭建Appium环境文档,没有之一

Mysql NDB Cluster 集群搭建实战全网最详细