로딩
요청 처리 중입니다...

fs - html

 fs - html

fs.promises로 비동기화 왜? 서버가 시작된 이후로 동기로 파일을 읽어오게 되면, 사용자가 많은경우, 서버 지연이 발생한다. const http = require('http'); const fs = require('fs').promises; const server = http.createServer(async (req,res)=>{ try{ res.writeHead(200,{'Content-Type':'text/html; charset=utf-8'}); const data = await fs.readFile('.

/server.html'); // promise화 res.end(data); }catch(error){ console.error(error); res.writeHead(200,{'Content-Type':'text/plain; charset=utf-8'}); } }).listen(8080); server.on('listening',()=>{ console.log('80...

# fs로html가져오기 # Node

원문 링크 : fs - html