Node入门--7-->Http创建服务器

mac2022-06-30  24

Why:可以搭建属于自己服务器What:

    

How // 1.通过http模块,创建本地服务器var http = require('http');// 2.通过对象创建服务器方法var server = http.createServer(function (req,res) {console.log("客户端向服务器发送请求" + req.url); res.writeHead(200, {"Content-type":"text/plain"}); res.end("Server is Working!");//可以返回html,json等文件});// 3.服务对象监听服务器地址以及端口号server.listen(8888, '127.0.0.1');

 

转载于:https://www.cnblogs.com/Afanty/p/6924898.html

最新回复(0)