// 引入Node.js 自带的 http 模块,并且把它赋值给 http 变量 const http = require('http'); // 创建createServer方法用于接受http客户端请求及返回响应的http服务器程序 http.createServer(function (req,res){// 发送 HTTP 头部 // HTTP 状态值: 200 : OK // 内容类型: text/plain res.writeHead(200,{'Content-Type':'text/plain'}); // 通过响应对象的end方法输入html代码并结束响应流 res.end('Hello World\n');
}).listen(8888); //createServer函数会返回 一个对象,这个对象有一个叫做 listen 的方法, // 这个方法有一个数值参数, 指定这个 HTTP 服务器监听的端口号。
推荐阅读
- JavaScript|JavaScript: BOM对象 和 DOM 对象的增删改查
- web前端笔记|web前端学习-第一天
- JAVA框架之路|spring-boot笔记-工程搭建(一)
- spring|Java学习笔记(SpringMVC)
- URL协议和HTTP协议
- Web服务器的环境