server.js
var http = require("http");
http.createServer(function(request,response){
//发送http头部
//http状态 : 200 :ok
//内容类型:text/plain
response.writeHead(200,{'Content-Type':'text/plain'});
//发送响应数据“hello world”
response.end('Hello world!')
}).listen(8888)
console.log('server running at http://127.0.0.1:8888')
运行nodejs 程序
在对应的程序路径下面 运行nodejs 程序 :node ‘程序名称’

效果:

本文介绍如何使用Node.js创建一个简单的HTTP服务器,并监听8888端口返回文本信息。文章详细展示了创建服务器的代码实现过程及运行方法。

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



