读书人

windows cygwin node.js环境筹建

发布时间: 2013-02-19 11:11:40 作者: rapoo

windows cygwin node.js环境搭建
只做记录使用:

cygwin:

?

Develgcc-g++: C++ compilergcc-mingw-g++: Mingw32 support headers and libraries for GCC C++gcc4-g++: G++ subpackagegit: Fast Version Control System core filesmake: The GNU version of the ‘make’ utilityopenssl-devel: The OpenSSL development environmentpkg-config: A utility used to retrieve information about installed librarieszlib-devel: The zlib compression/decompression library (development)Editorvim: Vi IMproved enhanced vi editorPython全部Web 分类wget: Utility to retrieve files from the WWW via HTTP and FTPcurl: 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,输入:

    varhttp = 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/');

回到cygwin命令窗口中输入 node /example.js 回车。

命令窗口中显示 Server running at http://127.0.0.1:8888/

打开浏览器,输入http://127.0.0.1:8888/,成功了吧!

npm下载、安装、使用

npm是nodejs的软件包管理器,可以用它安装所需软件包并发布自己为nodejs写的软件包,它还管理软件包的依赖关系并做了其它一些很酷的事情。

    一行命令下载并安装npm

    $ curl http://npmjs.org/install.sh | sh

    npm安装node扩展包,同样是一行命令下载并安装好软件包

    $ npm install <包名>

读书人网 >JavaScript

热点推荐