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

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

  • 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');

 

相关文章:

  • 2021-07-28
  • 2021-06-12
  • 2021-11-20
  • 2022-12-23
  • 2021-08-09
  • 2022-02-10
  • 2021-05-25
猜你喜欢
  • 2021-07-18
  • 2022-02-03
  • 2021-11-24
  • 2021-07-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案