通用node.js环境搭建

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/LeonWang_Fly/article/details/50993880

1. 下载并安装node.js,这一步没没什么难的,重点要注意你电脑32位还是64位(一定要选择对应的)。

2. 设置全局npm路径(路径自定义,最好在你的node安装目录下)

npm config set cache "D:\Program Files\nodejs\npm_cache"
npm config set prefix "D:\Program Files\nodejs\npm_global"

若报错请手动在相应路径下建相应目录(Error: ENOENT, stat ‘C:\Users\lenovo[user]Roaming\npm’ 若报这个错误同样需要检查该目录是否存在)

3 .环境变量设置

path设置,一般会自行设置nodejs的环境变量,如果没有设置,需手动配置

4. python 2.7以上版本安装、visual studio 2012 或 以上(2010没试过)。这俩东东可能提供node自身或者某些插件的运行编译环境。

5. 安装第三方插件

命令:npm install -g 插件名@版本号(@版本号可以省略,省略默认安装最新的)
常用插件

npm install -g supervisor     用于自动热部署
npm install -g express           开发框架
npm install -g express-generator   用于自动生成项目架构
npm install -g generator-kraken

6.安装开发工具

功能强大的可以选择webstorm,轻量级的话Sublime Text 3是一个不错的选择,当然也可以使用其他的。

搭建心得:
1) 安装插件有时在安装后运行提示找不到该命令,那么首先确定下这个插件有没有正确安装,确定安装目录或者上层能不能找到该命令,找到的话再检查该命令是否在path环境变量中。
2) 安装的插件出问题后可以在github上面看看相关版本及使用说明,可能新的版本中有相关分支调整(如express后期分成express和express-generator)。

安装出现错误一般关注几个问题:
1.vs、python是否安装
2.版本问题 node、npm

错误解决:

E:\workspaces\IPDEV\node_modules\bcrypt>node "D:\Program Files\nodejs\node_modul
es\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild
在此解决方案中一次生成一个项目。若要启用并行生成,请添加“/m”开关。
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.t
argets(64,5): error MSB8020: The build tools for Visual Studio 2012 (Platform T
oolset = 'v110') cannot be found. To build using the v110 build tools, please i
nstall Visual Studio 2012 build tools.  Alternatively, you may upgrade to the c
urrent Visual Studio tools by selecting the Project menu or right-click the sol
ution, and then selecting "Upgrade Solution...". [E:\workspaces\IPDEV\node_modu
les\bcrypt\build\bcrypt_lib.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\12.0\bin\msbuild.exe` fail
ed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (D:\Program Files\nodejs\node_modules\
npm\node_modules\node-gyp\lib\build.js:267:23)
gyp ERR! stack     at ChildProcess.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:810:
12)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "node" "D:\\Program Files\\nodejs\\node_modules\\npm\\node_modu
les\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd E:\workspaces\IPDEV\node_modules\bcrypt
gyp ERR! node -v v0.10.32
gyp ERR! node-gyp -v v1.0.1
gyp ERR! not ok

> [email protected] install E:\workspaces\IPDEV\node_modules\iconv
> node-gyp rebuild

你安装的visual studio版本必须与你node设置的版本一致,否则出此错误,解决办法:运行npm config set msvs_version 2012进行设置(2012为版本号,以你机器上安装的版本号为准)

猜你喜欢

转载自blog.csdn.net/LeonWang_Fly/article/details/50993880