lindakun 发表于 2013-2-7 03:42:39

windows下安装node.js及npm

现如今,node大热,不弄弄,那不落伍了!服务器端嘛,首先还是配置环境,第一步走出去了,后面的就好说了,一步步来嘛!我平时都是用的windows,这里就只记录windows啦!

第一步:安装Cygwin

Cygwin网站:http://cygwin.com/,Cygwin是什么就不多说了,反正是必须的!先下载setup文件,就算安装完了这个文件也别删,以后万一还有用得着的地方!如果首次安装有些包忘记装了,还得用这个再次安装!我一开始就忘记了好几个包,导致浪费了好多时间!主要是记得第一个界面时选择“install from internet”,否则就会失败!
这里要装的包有:
Devel


[*]gcc-g++: C++ compiler
[*]gcc-mingw-g++: Mingw32 support headers and libraries for GCC C++
[*]gcc4-g++: G++ subpackage
[*]git: Fast Version Control System – core files
[*]make: The GNU version of the ‘make’ utility
[*]openssl-devel: The OpenSSL development environment
[*]pkg-config: A utility used to retrieve information about installed libraries
[*]zlib-devel: The zlib compression/decompression library (development)
Editor


[*]vim: Vi IMproved – enhanced vi editor
Python


[*]全部
Web 分类


[*]wget: Utility to retrieve files from the WWW via HTTP and FTP
[*]curl: Multi-protocol file transfer command-line tool
接下来就是下载了,有朋友建议选择日本的镜像,挺快!然后就是漫长的等待了。
如果你是win7用户

[*]cmd命令行
[*]进入cygwin安装目录下的bin子目录
[*]运行ash.exe进入shell模式
[*]./rebaseall -v
[*]没有错误,完成,exit退出ash,关闭命令行窗口
第二步:安装Node.js


[*]运行Cygwin
[*]输入 wget http://nodejs.org/dist/node-v0.4.7.tar.gz 回车,下载node.js安装包。
[*]输入 tar xf node-v0.4.7.tar.gz 回车。
[*]输入 cd node-v0.4.7 回车。
[*]输入 ./configure 回车。
[*]输入 make 回车,可能要等一段时间!
[*]输入 make install 回车。
一切正常的话,node.js安装成功!现在可以输入 node –version 回车,查看node.js版本啦
第三步:设置DNS并创建测试文件

cygwin的安装目录下找到etc文件夹,创建一个resolv.conf,添加代码:

nameserver 8.8.8.8
nameserver 8.8.4.4

保存,关闭!
现在可以开始测试了,返回父目录,也就是cygwin的安装目录,新建一个js文件,命名test.js,输入:
<div class="hl-surround">
[*]var http = require('http');
[*]http.createServer(function (request, response) {
[*]  response.writeHead(200, {'Content-Type': 'text/html'});
[*]  response.end('<b>Hello World</b>');
[*]}).listen(8888);
[*]console.log('Server running at http://127.0.0.1:8888/');
页: [1]
查看完整版本: windows下安装node.js及npm