nodejs简单例子

发布时间 2023-04-08 14:23:19作者: 漫漫长路

 

 

post

const http = require('http')

const server = http.createServer((req,res)=>{
    if(req.method === 'POST'){
        //数据格式
        console.log('content-type',req.headers['content-type'])
        //接受数据
        let postData = ""
        req.on('data',chunk=>{
            postData += chunk.toString()
        })
        req.on('end',()=>{
            console.log(postData,'2121')
            res.end('hello world')
        })
    }
})

server.listen(8000);
console.log('ok')