Nodejs实现Httpserver服务

创建Httpserver.js

1.导入http模块

const http = require('http');

2.创建一个httpServer服务

http.createServer(function(request,response){
    // 浏览器将以text/plain的方式解析数据
    response.writeHead(200,{'content-type' : 'text/plain'});
    // 输出给浏览器
    response.end("Hello server!!!"); 
}).listen(8888);
  console.log("您启动的服务是:http://localhost:8888已启动成功了!!!")

3.启动服务

ctrl+shift+y打开终端,输入node Httpserver.js

 4.打开浏览器访问http://localhost:8888,即可访问到。

 

 5.停止服务:ctrl+c

posted @ 2021-03-25 16:46  nyfq  阅读(197)  评论(0)    收藏  举报