Node.js http fs
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Node.js http fs相关的知识,希望对你有一定的参考价值。
?????????res div func node.js ?????? ????????? dex aaa ring
const http=require(???http???); const fs=require(???fs???); var server = http.createServer(function(req, res){ var file_name = ???./www??? + req.url; // req.url => ???/index.html??? // ?????? => ???./www.index.html??? // ???./www??? + req.url // ?????????????????????url (req.url), ?????? index.html??????????????????????????????.www?????????????????????index.html fs.readFile(file_name, function(err, data){ if(err){ res.write(???404???); }else{ res.write(data); } res.end(); }) }); server.listen(8080);
const fs = require(???fs???); // ???????????? fs => file syestem // fs.readFile(?????????, ??????) fs.readFile(???aaa.txt???, function(err, data){ if(err){ console.log(??????????????????); }else{ console.log(data.toString()); } }); // fs.writeFile(?????????, ??????, ??????) fs.writeFile("bbb.txt","gdgignrgkwng", function(err){ console.log(err); })
以上是关于Node.js http fs的主要内容,如果未能解决你的问题,请参考以下文章