# tinyhttp
**Repository Path**: studvc/tinyhttp
## Basic Information
- **Project Name**: tinyhttp
- **Description**: π¦ 0-legacy, tiny & fast web framework as a replacement of Express
- **Primary Language**: Unknown
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2021-01-31
- **Last Updated**: 2021-01-31
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README

tinyhttp
β‘ Tiny web framework as a replacement of Express
[][site-url] [][npm-url] [][github-actions]
[][codecov]
 [][codacy-url] [][gh-url] [][license]
_**tinyhttp**_ is a modern [Express](https://expressjs.com/)-like web framework written in TypeScript and compiled to native ESM, that uses a bare minimum amount of dependencies trying to avoid legacy hell.
Here is a short list of most important features that tinyhttp has:
- β‘ [2x faster](benchmark) than Express
- β Full Express middleware support
- βͺ Async middleware support
- β Native ESM and CommonJS support
- π No legacy dependencies, just the JavaScript itself
- π¨ Types out of the box
- π₯ Prebuilt middleware for modern Node.js
Visit [tinyhttp website](https://tinyhttp.v1rtl.site) for docs, guides and middleware search.
## Install
tinyhttp requires [Node.js 12.4.0 or newer](https://node.green/#ES2019). It is recommended to use [pnpm](https://pnpm.js.org/), although it isn't required.
```sh
# npm
npm i @tinyhttp/app
# pnpm
pnpm i @tinyhttp/app
# yarn
yarn add @tinyhttp/app
```
## Docs
You can see the documentation [here](https://tinyhttp.v1rtl.site/docs).
## Get Started
tinyhttp is compiled to ESM (and legacy CommonJS) so you can use `import` / `export` syntax in Node.js with it.
To setup a Node ESM package, put `"type": "module"` in the package.json file, like this:
```json
{
"type": "module"
}
```
Another option would be using an `.mjs` extension, then you don't need to put that `"type"` field in package.json.
For more info, check out the [ECMAScript Modules Node.js documentation](https://nodejs.org/api/esm.html).
From now on you can use named imports for ESM modules and default imports for CommonJS modules in your project.
The app structure is quite similar to Express, except that you need to import `App` from `@tinyhttp/app` instead of default import from `express`.
```ts
import { App } from '@tinyhttp/app'
import { logger } from '@tinyhttp/logger'
const app = new App()
app
.use(logger())
.use(function someMiddleware(req, res, next) {
console.log('Did a request')
next()
})
.get('/', (_, res) => {
res.send('Hello World
')
})
.get('/page/:page/', (req, res) => {
res.status(200).send(`You just opened ${req.params.page}`)
})
.listen(3000)
```
See tinyhttp ["Learn" page](https://tinyhttp.v1rtl.site/learn) for complete guide.
## Middlewares
tinyhttp offers a list of premade middleware for common tasks, such as [session](https://tinyhttp.v1rtl.site/mw/session), [logger](https://tinyhttp.v1rtl.site/mw/logger) and [jwt](https://tinyhttp.v1rtl.site/mw/jwt).
Search and explore the full list at [middleware search page](https://tinyhttp.v1rtl.site/mw).
## Comparison
See [COMPARISON.md](COMPARISON.md).
## Benchmarks
Check [benchmark](benchmark) folder.
## Contributing
See [CONTRIBUTING.md](CONTRIBUTING.md).
## Contributors β¨
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
## Supporters π°
These amazing people supported tinyhttp financially:
## License
MIT Β© [v1rtl](https://v1rtl.site)
[site-url]: https://tinyhttp.v1rtl.site
[npm-url]: https://npmjs.com/package/@tinyhttp/app
[codecov]: https://codecov.io/gh/talentlessguy/tinyhttp
[github-actions]: https://github.com/talentlessguy/tinyhttp/actions
[license]: https://github.com/talentlessguy/tinyhttp/blob/master/LICENSE
[gh-url]: https://github.com/talentlessguy/tinyhttp
[codacy-url]: https://www.codacy.com/manual/talentlessguy/tinyhttp