node核心 http模块

node作为服务器更多的是web服务器

http模块

首先:http是一个协议。里面有通信机制,状态码一大堆乱七八糟的东西。自己写猴年马月都写不出来,这个对象帮我们集成。直接用

服务器对象: http.createSever()【快速搭建一个服务器,集成好】

let http = require('http')

http.createServer(() => {
    content
}).listen(8088)
//当访问localhost:8088 content就会输出到服务器
let http = require('http')
let fs = require('fs')
http.createServer((request, response) => {
   console.log(request.url)
    fs.readFile(`./${request.url}`, (err, data) => {
        if (err) {

        } else {
            response.end(data)
        }
    })
}).listen(8088)
//当访问localhost:8088 content就会输出到服务器

猜你喜欢

转载自www.cnblogs.com/-constructor/p/12371589.html