Skip to content

How to create a simple server

Daisho Komiyama edited this page May 24, 2023 · 1 revision
const http = require('http')
const fs = require('fs')

const server = http.createServer((req, res) => {
    res.writeHead(200, { 'Content-Type': 'text/html' })
    fs.createReadStream(__dirname + '/index.html').pipe(res)
})

server.listen(3000, () => console.log('listening on 3000...'))
Clone this wiki locally