// 说明
Node API 版本为 v0.10.31。
中文参考:http://nodeapi.ucdok.com/#/api/
本段为博主注解。
目录
● 概要
概要
一个以 ’Hello World‘ 作为响应的以 Node 编写的 web 服务器:
1 var http = require(‘http‘); 2 3 http.createServer(function (request, response) { 4 response.writeHead(200, {‘Content-Type‘: ‘text/plain‘}); 5 response.end(‘Hello World\n‘); 6 }).listen(8124); 7 8 console.log(‘Server running at http://127.0.0.1:8124‘);
要运行服务器,需要将代码输入一个名为 example.js 的文件并通过 node 程序执行
> node example.js Server runing at http://127.0.0.1:8124/
文档中所有的例子都可以类似地运行。
时间: 2024-12-26 08:00:03