readFileSyncを使用したホームの表示


const http = require('http')
const {readFileSync} = require('fs')
const homepage = readFileSync('./navbar-app/index.html', 'utf-8')

const server = http.createServer((req, res)=>{
    const url = req.url
    //home page
    if(url === '/'){
        res.writeHead(200, {'content-type':'text/html'})
        res.write(homepage)
        res.end()
    }
    else if(url === '/about'){
        res.writeHead(200, {'content-type':'text/html'})
        res.write('<h1>about page<h2>')
        res.end()
    }
    // 404
    else{
        res.writeHead(404, {'content-type':'text/html'})
        res.write('<h1>page not found<h2>')
        res.end()
    }
})
server.listen(5000)