http 模块实现web服务器

阅读 74

2022-02-16

1.引用node内置模块http

        var http=require("http");

2.使用模块http创建服务

        var server=http.createServer(function(req,res){

                //(1)准备一个html文档的字符串

            var html=???;

                //(2)使用res响应对象把html文档字符串输出的浏览器中

            res.end(html);

        })

3.创建服务监听

        server.listen(8080);

4.运行项目

        node xx.js

5.测试

        http://localhost:8080

精彩评论(0)

0 0 举报