const http=require (‘http‘); //导入模块
const PORT=3000; //设置端口号3000(3000 5000 6000 9000)
const HOSTNAME=‘localhost‘; //或"127.0.0.1"
http.createServer((req,res)=>{
res.writeHead(‘Content-type:text/html,charset:utf-8‘);
res.writeHead( 200, { //设置响应头 状态码!!!!!!!!!!!
‘Content-Type‘: ‘text/html;charset=utf8‘ //字符编码 ‘Content-type’:‘text/html;charset:utf-8‘ ;
})
res.write(‘xxxxxxxx‘);
res.end(‘结束xxx‘)
}).listen(PORT,HOSTNAME,()=>{
console.log(`The Server is running at: http://${ HOSTNAME }:${PORT}`)
})
原文地址:https://www.cnblogs.com/zhangzhouy/p/11355753.html
时间: 2024-09-30 17:33:05