node.js是个基于javascript的服务器端。
os: ubuntu 12.04 64bit
nodejs: 0.8.8-1chl1~precise1
1.安装
sudo apt-get install nodejs
2.测试
nodejs --version
3.运行第一个node.js的程序
在主文件夹中创建example.js,编辑文本
JavaScript代码
- var http = require('http');
- http.createServer(function (req, res) {
- res.writeHead(200, {'Content-Type': 'text/plain'});
- res.end('Hello Node.js');
- }).listen(8124, "127.0.0.1");
- console.log('Server running at http://127.0.0.1:8124/');
在命令行中
nodejs example.js
浏览器中浏览http://127.0.0.1:8124/ ,浏览器中出现Hello Node.js