目录文件如

httpFile.js如下:
const httpd = require("http");
const fs = require("fs");
//创建服务
httpd.createServer((req,res)=>{
//读取www文件夹下的路径
fs.readFile(`www${req.url}`,(err,data)=>{
//失败返回404
if(err){
res.writeHeader(404);
res.write('<h1>404</h1>'); }else{ //成功返回页面 res.write(data); } res.end(); }) }).listen(8082); console.log('runing......')
访问

访问1.html

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
长按识别二维码并关注微信
更方便到期提醒、手机管理