Windows7下搭建Node.js环境

2011-04-06
2分钟阅读时长
700字
阅读
Featured Image
  1. 下载并安装Cygwin 及Node.js安装依赖的附加组件

cygwin下载:  http://cygwin.com/setup.exe (下载点最好选择台湾或日本的临近点,速度快)

附加组件选择:

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  (github方式下载时用)
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

  1.  由于操作系统为 windows 7 (Windows Vista以后版本),需要在ash模式下执行rebaseall才能保证 node.js的编译通过

a. 进入 cygwin安装目录/bin/
b. 运行ash.exe
c.  执行./rebaseall -v 命令
d. 正常情况下就OK通过,而我编译出现错误,提示系统临时目录无写入 权限
e.  我编译出现错误,提示系统临时目录无写入权限,遂,手动修改了 rebaseall 文件的 83行处代码,如下:

# TmpDir="${TMP:-${TEMP:-/tmp}}"
TmpDir="D:/servers/cygwin_local/temp"
  1. 启动cygwin下载 node.js源码编译并安装
$ cd /
$ git clone git://github.com/joyent/node.git
$ cd node
$ ./configure
$ make
$ make install
  1.  设置DNS

cygwin内部使用windows的DNS查询,且node.js采用c-ares函数库,而c-ares函数库读取的  /etc/resolv.conf 里的nameserver配置,

所以需要手动建立 /etc/resolv.conf , 并增加以下nameserver 来让node.js执行网络操作时正常运行:

$ vi /ect/resolv.conf

nameserver 8.8.8.8
nameserver 8.8.4.4
  1. 测试node.js环境

查看下 node安装信息:

node --version

写个简单的 Http Server来测试下node.js环境,保存一下代码为/worksapce/test.js:

var http = require('http'), port = 8888;

http.createServer(function (request, response) {
response.writeHead(200, { 'Content-Type': 'text/html;charset=utf-8;' });
response.end('<h1>你好世界!</h1>');
}).listen(port);

console.log('服务已启动 http://127.0.0.1:' + port + '/');
$ node /workspace/test.js

开打浏览器访问 http://127.0.0.1:8888  查看效果

Avatar
zfkun 喜欢游戏、热爱技术、追求艺术、崇尚自由、渴望精彩、最爱唠叨