nodejs安装(转载)
一、Node.js 简介
Node.js:服务器端的 JavaScript 运行环境,它具有无阻塞和事件驱动等特色,采用 V8 引擎,实现了类似 Apache 和 Nginx 的 Web 服务,让你可以通过它来搭建基于 JavaScript 的 Web App。参考官方:http://nodejs.org/,Node.js 支持 Linux、Macintosh、Solaris、Windows/Cygwin、FreeBSD、OpenBSD,编译系统需 Python 2.4以上版本支持。
二、Node.js 安装
1、安装编译环境,>sudo apt-get install g++ c++ curl libssl-dev apache2-utils git-core curl
2、下载Node安装包,>wget http://nodejs.org/dist/node-v0.3.0.tar.gz
3、编译安装,步骤如下:
>./configure //注:如果不需SSL,可加入选项-without-ssl
>make
>make install
4、安装成功,默认路径为:/usr/local/bin/node
三、Node.js 应用
1、安装成功后先写“Hello World!”简单测试一下,代码如下:
view plaincopy to clipboardprint?//filename: app.js var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(8000, "127.0.0.1"); console.log('Server running at http://127.0.0.1:8000/');