UNPKG

@fastify/send

Version:

Better streaming static file server with Range and conditional-GET support

16 lines (11 loc) 384 B
'use strict' const http = require('node:http') const send = require('..') const path = require('node:path') const indexPath = path.join(__dirname, 'index.html') const server = http.createServer(async function onRequest (req, res) { const { statusCode, headers, stream } = await send(req, indexPath) res.writeHead(statusCode, headers) stream.pipe(res) }) server.listen(3000)