Star on GitHub

tinyhttp is a modern, lightweight and modular Express-like web framework for Node.js.

Quick start

pnpm i @tinyhttp/app @tinyhttp/logger
import { App } from '@tinyhttp/app'
import { logger } from '@tinyhttp/logger'

const app = new App()

app
  .use(logger())
  .get('/', (_, res) => void res.send('<h1>Hello World</h1>'))
  .get('/page/:page/', (req, res) => {
    res.status(200).send(`
    <h1>Some cool page</h1>
    <h2>URL</h2>
    ${req.url}
    <h2>Params</h2>
    ${JSON.stringify(req.params, null, 2)}
  `)
}).listen(3000)
http://localhost:3000/

Some cool page

URL

/page/test

Params

{ "page": "test" }

Features

tinyhttp is a modern Express-like web framework written in TypeScript and compiled to native ESM, that uses a bare minimum amount of dependencies trying to avoid legacy hell. With depending only on 6 modules (5 of which are tinyhttp's), it gives you routing, req / res extensions, eTag generation and more.

Full compatability with Express

All middleware that was created for Express, works flawlessly with tinyhttp, including typings. In fact, any middleware that uses (req: IncomingMessage, res: ServerResponse, next?: (err?: any) => void) for function arguments, will work with tinyhttp. Check out tinyhttp + express-graphql integration for an example of using Express middleware.

Async middleware support

Unlike Express, tinyhttp supports async / await for routes. There are proper typings for async handlers, and a function checker inside tinyhttp to resolve async functions, and execute sync ones. To say shorter, both sync and async work fine. Check async or mongodb examples to see how to make async handlers.

Prebuilt middleware for the smoothest experience

A majority of express middlewares is quite old and don't provide ESM versions and possibly may have type conflicts (even though 90% of the time Express wares' types are ok w/ tinyhttp). So, because of this, we've built a list of our own middlewares for most common tasks in backend development, including logger, JWT and CORS middlewares.

Completely modular

(Almost) all parts of tinyhttp are splitted into modules. Feel free to use @tinyhttp/etag or @tinyhttp/cookie in any other HTTP application with any (or without) web framework . Same goes to (almost) all of the middlewares.

Projects using tinyhttp