标签:细节问题 browser tcp move 状态码 hello 使用 路径 url
count http = require('http')
const server = http.createServer()
API:
API:
API:
const http = require('http')
const hostname = '127.0.0.1'
const port = '20000'
const server = http.createServer((req, res) => {
res.statusCode = 200
res.setHeader('Content-Type', 'text/plain')
res.end('Hello World\n')
})
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}`)
})
html:
const http = require('http')
const hostname = '127.0.0.1'
const port = '20001'
const server = http.createServer((req, res) => {
// 响应文本类型的html,响应格式 utf-8
res.setHeader('Content-Type', 'text/html; charset=utf-8')
res.end(`<h1>hello你好,世界</h1>`)
})
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`)
})
标签:细节问题 browser tcp move 状态码 hello 使用 路径 url
原文地址:https://www.cnblogs.com/liea/p/11832573.html