node 实现监听端口号

// 引入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 服务器监听的端口号。

    推荐阅读