Node.js学习001-hello world
Node.js学习001-hello world
var http = require('http');
http.createServer(function (request, response) {
// 发送 HTTP 头部
// HTTP 状态值: 200 : OK
// 内容类型: text/plain
if(request.url != "/favicon.ico"){
response.writeHead(200, {'Content-Type': 'text/plain'});
console.log("访问");
response.write("Hello world!")
response.end('');
}
}).listen(8888);
// 终端打印如下信息
console.log('Server running at http://127.0.0.1:8888/');
本文介绍如何使用Node.js创建一个简单的HTTP服务器,通过调用http模块并定义回调函数来响应客户端请求,展示Hello World!信息。服务器监听8888端口,并在控制台输出运行状态。
1284

被折叠的 条评论
为什么被折叠?



