---
name: fastify
summary: "Fastify is a high-performance Node.js web framework built around a powerful plugin/encapsulation architecture and JSON Schema-based validation and serialization. It aims to minimize per-request overhead while keeping a clean, developer-friendly API for building HTTP APIs and services."
language: JavaScript
license: MIT
repo: https://github.com/fastify/fastify
source: https://opensources.dev/resource/fastify
health: 100
---

# fastify

Fastify is a high-performance Node.js web framework built around a powerful plugin/encapsulation architecture and JSON Schema-based validation and serialization. It aims to minimize per-request overhead while keeping a clean, developer-friendly API for building HTTP APIs and services.

[![CI](https://github.com/fastify/fastify/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/fastify/fastify/actions/workflows/ci.yml)
[![Package Manager
CI](https://github.com/fastify/fastify/actions/workflows/package-manager-ci.yml/badge.svg?branch=main)](https://github.com/fastify/fastify/actions/workflows/package-manager-ci.yml)
[![Web
site](https://github.com/fastify/fastify/actions/workflows/website.yml/badge.svg?branch=main)](https://github.com/fastify/fastify/actions/workflows/website.yml)
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)
[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/7585/badge)](https://bestpractices.coreinfrastructure.org/projects/7585)

[![NPM
version](https://img.shields.io/npm/v/fastify.svg?style=flat)](https://www.npmjs.com/package/fastify)
[![NPM
downloads](https://img.shields.io/npm/dm/fastify.svg?style=flat)](https://www.npmjs.com/package/fastify)
[![Security Responsible
Disclosure](https://img.shields.io/badge/Security-Responsible%20Disclosure-yellow.svg)](https://github.com/fastify/fastify/blob/main/SECURITY.md)
[![Discord](https://img.shields.io/discord/725613461949906985)](https://discord.gg/fastify)
[![Contribute with Gitpod](https://img.shields.io/badge/Contribute%20with-Gitpod-908a85?logo=gitpod&color=blue)](https://gitpod.io/#https://github.com/fastify/fastify)
[![Open Collective backers and sponsors](https://img.shields.io/opencollective/all/fastify)](https://github.com/sponsors/fastify#sponsors)

An efficient server implies a lower cost of the infrastructure, better
responsiveness under load, and happy users. How can you efficiently handle the
resources of your server, knowing that you are serving the highest number of
requests possible, without sacrificing security validations and handy
development?

Enter Fastify. Fastify is a web framework highly focused on providing the best
developer experience with the least overhead and a powerful plugin architecture.
It is inspired by Hapi and Express and as far as we know, it is one of the
fastest web frameworks in town.

The `main` branch refers to the Fastify `v5` release.
Check out the [`4.x` branch](https://github.com/fastify/fastify/tree/4.x) for `v4`.

### Table of Contents

- [Quick start](#quick-start)
- [Install](#install)
- [Example](#example)
- [Core features](#core-features)
- [Benchmarks](#benchmarks)
- [Documentation](#documentation)
- [Ecosystem](#ecosystem)
- [Support](#support)
- [Team](#team)
- [Hosted by](#hosted-by)
- [License](#license)

### Quick start

Create a folder and make it your current working directory:

```sh
mkdir my-app
cd my-app
```

Generate a fastify project with `npm init`:

```sh
npm init fastify
```

Install dependencies:

```sh
npm i
```

To start the app in dev mode:

```sh
npm run dev
```

For production mode:

```sh
npm start
```

Under the hood `npm init` downloads and runs [Fastify
Create](https://github.com/fastify/create-fastify), which in turn uses the
generate functionality of [Fastify CLI](https://github.com/fastify/fastify-cli).

### Install

To install Fastify in an existing project as a dependency:

```sh
npm i fastify
```

### Example

```js
// Require the framework and instantiate it

// ESM
import Fastify from 'fastify'

const fastify = Fastify({
  logger: true
})
// CommonJs
const fastify = require('fastify')({
  logger: true
})

// Declare a route
fastify.get('/', (request, reply) => {
  reply.send({ hello: 'world' })
})

// Run the server!
fastify.listen({ port: 3000 }, (err, address) => {
  if (err) throw err
  // Server is now listening on ${address}
})
```

With async-await:

```js
// ESM
import Fastify from 'fastify'

const fastify = Fastify({
  logger: true
})
// CommonJs
const fastify = require('fastify')({
  logger: true
})

fastify.get('/', async (request, reply) => {
  reply.type('application/json').code(200)
  return { hello: 'world' }
})

fastify.listen({ port: 3000 }, (err, address) => {
  if (err) throw err
  // Server is now listening on ${address}
})
```

Do you want to know more? Head to the Getting Started.
If you learn best by reading code, explore the official [demo](https://github.com/fastify/demo).

> ## Note
> `.listen` binds to the local host, `localhost`, interface by default
> (`127.0.0.1` or `::1`, depending on the operating system configuration). If
> you are running Fastify in a container (Docker,
> [GCP](https://cloud.google.com/), etc.), you may need to bind to `0.0.0.0`. Be
> careful when listening on all interfaces; it comes with inherent
> [security
> risks](https://web.archive.org/web/20170711105010/https://snyk.io/blog/mongodb-hack-and-secure-defaults/).
> See [the documentation](./docs/Reference/Server.md#listen) for more
> information.

### Core features

- **Highly performant:** as far as we know, Fastify is one of the fastest web
  frameworks in town, depending on the code complexity we can serve up to 76+
  thousand requests per second.
- **Extensible:** Fastify is fully extensible via its hooks, plugins, and
  decorators.
- **Schema-based:** even if it is not mandatory we recommend using [JSON
  Schema](https://json-schema.org/) to validate your routes and serialize your
  outputs. Internally Fastify compiles the schema in a highly performant
  function.
- **Logging:** logs are extremely important but are costly; we chose the best
  logger to almost remove this cost, [Pino](https://github.com/pinojs/pino)!
- **Developer friendly:** the framework is built to be very expressive and help
  developers in their daily use without sacrificing performance and
  security.

### Benchmarks

**Machine:** EX41S-SSD, Intel Core i7, 4Ghz, 64GB RAM, 4C/8T, SSD.

**Method**: `autocannon -c 100 -d 40 -p 10 localhost:3000` * 2, taking the
second average

FrameworkVersionRouter?Requests/secExpress4.17.3✓14,200hapi20.2.1✓42,284Restify8.6.1✓50,363Koa2.13.0✗54,272**Fastify****4.0.0****✓****77,193**-`http.Server`16.14.2✗74,513

These benchmarks taken using [https://github.com/fastify/benchmarks](https://github.com/fastify/benchmarks). This is a
synthetic "hello world" benchmark that aims to evaluate the framework overhead.
The overhead that each framework has on your application depends on your
application. You should **always** benchmark if performance matters to you.

## Documentation

- [`Getting Started`](./docs/Guides/Getting-Started.md)
- [`Guides`](./docs/Guides/Index.md)
- [`Server`](./docs/Reference/Server.md)
- [`Routes`](./docs/Reference/Routes.md)
- [`Encapsulation`](./docs/Reference/Encapsulation.md)
- [`Logging`](./docs/Reference/Logging.md)
- [`Middleware`](./docs/Reference/Middleware.md)
- [`Hooks`](./docs/Reference/Hooks.md)
- [`Decorators`](./docs/Reference/Decorators.md)
- [`Validation and Serialization`](./docs/Reference/Validation-and-Serialization.md)
- [`Fluent Schema`](./docs/Guides/Fluent-Schema.md)
- [`Lifecycle`](./docs/Reference/Lifecycle.md)
- [`Reply`](./docs/Reference/Reply.md)
- [`Request`](./docs/Reference/Request.md)
- [`Errors`](./docs/Reference/Errors.md)
- [`Content Type Parser`](./docs/Reference/ContentTypeParser.md)
- [`Plugins`](./docs/Reference/Plugins.md)
- [`Testing`](./docs/Guides/Testing.md)
- [`Benchmarking`](./docs/Guides/Benchmarking.md)
- [`How to write a good plugin`](./docs/Guides/Write-Plugin.md)
- [`Plugins Guide`](./docs/Guides/Plugins-Guide.md)
- [`HTTP2`](./docs/Reference/HTTP2.md)
- [`Long Term Support`](./docs/Reference/LTS.md)
- [`TypeScript and types support`](./docs/Reference/TypeScript.md)
- [`Serverless`](./docs/Guides/Serverless.md)
- [`Recommendations`](./docs/Guides/Recommendations.md)

## Ecosystem

- [Core](./docs/Guides/Ecosystem.md#core) - Core plugins maintained by the
  *Fastify* [team](#team).
- [Community](./docs/Guides/Ecosystem.md#community) - Community-supported
  plugins.
- [Live Examples](https://github.com/fastify/example) - Multirepo with a broad
  set of real working examples.
- [Discord](https://discord.gg/D3FZYPy) - Join our discord server and chat with
  the maintainers.

## Support

Please visit [Fastify help](https://github.com/fastify/help) to view prior
support issues and to ask new support questions.

Version 3 of Fastify and lower are EOL and will not receive any security or bug
fixes.

Fastify's partner, HeroDevs, provides commercial security fixes for all
unsupported versions at https://herodevs.com/support/fastify-nes.
Fastify's supported version matrix is available in the
Long Term Support documentation.

## Contributing

Whether reporting bugs, discussing improvements and new ideas, or writing code,
we welcome contributions from anyone and everyone. Please read the [CONTRIBUTING](./CONTRIBUTING.md)
guidelines before submitting pull requests.

## Team

*Fastify* is the result of the work of a great community. Team members are
listed in alphabetical order.

**Lead Maintainers:**

- [**Matteo Collina**](https://github.com/mcollina),
  [https://x.com/matteocollina](https://x.com/matteocollina), [https://www.npmjs.com/~matteo.collina](https://www.npmjs.com/~matteo.collina)
- [**Tomas Della Vedova**](https://github.com/delvedor),
  [https://x.com/delvedor](https://x.com/delvedor), [https://www.npmjs.com/~delvedor](https://www.npmjs.com/~delvedor)
- [**KaKa Ng**](https://github.com/climba03003),
  [https://www.npmjs.com/~climba03003](https://www.npmjs.com/~climba03003)
- [**Manuel Spigolon**](https://github.com/eomm),
  [https://x.com/manueomm](https://x.com/manueomm), [https://www.npmjs.com/~eomm](https://www.npmjs.com/~eomm)
- [**James Sumners**](https://github.com/jsumners),
  [https://x.com/jsumners79](https://x.com/jsumners79), [https://www.npmjs.com/~jsumners](https://www.npmjs.com/~jsumners)

### Fastify Core team

- [**Aras Abbasi**](https://github.com/uzlopak),
  [https://www.npmjs.com/~uzlopak](https://www.npmjs.com/~uzlopak)
- [**Harry Brundage**](https://github.com/airhorns/),
  [https://x.com/harrybrundage](https://x.com/harrybrundage), [https://www.npmjs.com/~airhorns](https://www.npmjs.com/~airhorns)
- [**Matteo Collina**](https://github.com/mcollina),
  [https://x.com/matteocollina](https://x.com/matteocollina), [https://www.npmjs.com/~matteo.collina](https://www.npmjs.com/~matteo.collina)
- [**Gürgün Dayıoğlu**](https://github.com/gurgunday),
  [https://www.npmjs.com/~gurgunday](https://www.npmjs.com/~gurgunday)
- [**Tomas Della Vedova**](https://github.com/delvedor),
  [https://x.com/delvedor](https://x.com/delvedor), [https://www.npmjs.com/~delvedor](https://www.npmjs.com/~delvedor)
- [**Carlos Fuentes**](https://github.com/metcoder95),
  [https://x.com/metcoder95](https://x.com/metcoder95), [https://www.npmjs.com/~metcoder95](https://www.npmjs.com/~metcoder95)
- [**Vincent Le Goff**](https://github.com/zekth)
- [**Luciano Mammino**](https://github.com/lmammino),
  [https://x.com/loige](https://x.com/loige), [https://www.npmjs.com/~lmammino](https://www.npmjs.com/~lmammino)
- [**Jean Michelet**](https://github.com/jean-michelet),
  [https://www.npmjs.com/~jean-michelet](https://www.npmjs.com/~jean-michelet)
- [**KaKa Ng**](https://github.com/climba03003),
  [https://www.npmjs.com/~climba03003](https://www.npmjs.com/~climba03003)
- [**Luis Orbaiceta**](https://github.com/luisorbaiceta),
  [https://x.com/luisorbai](https://x.com/luisorbai), [https://www.npmjs.com/~luisorbaiceta](https://www.npmjs.com/~luisorbaiceta)
- [**Maksim Sinik**](https://github.com/fox1t),
  [https://x.com/maksimsinik](https://x.com/maksimsinik), [https://www.npmjs.com/~fox1t](https://www.npmjs.com/~fox1t)
- [**Manuel Spigolon**](https://github.com/eomm),
  [https://x.com/manueomm](https://x.com/manueomm), [https://www.npmjs.com/~eomm](https://www.npmjs.com/~eomm)
- [**James Sumners**](https://github.com/jsumners),
  [https://x.com/jsumners79](https://x.com/jsumners79), [https://www.npmjs.com/~jsumners](https://www.npmjs.com/~jsumners)

### Fastify Plugins team

- [**Harry Brundage**](https://github.com/airhorns/),
  [https://x.com/harrybrundage](https://x.com/harrybrundage), [https://www.npmjs.com/~airhorns](https://www.npmjs.com/~airhorns)
- [**Simone Busoli**](https://github.com/simoneb),
  [https://x.com/simonebu](https://x.com/simonebu), [https://www.npmjs.com/~simoneb](https://www.npmjs.com/~simoneb)
- [**Dan Castillo**](https://github.com/dancastillo),
  [https://www.npmjs.com/~dancastillo](https://www.npmjs.com/~dancastillo)
- [**Matteo Collina**](https://github.com/mcollina),
  [https://x.com/matteocollina](https://x.com/matteocollina), [https://www.npmjs.com/~matteo.collina](https://www.npmjs.com/~matteo.collina)
- [**Gürgün Dayıoğlu**](https://github.com/gurgunday),
  [https://www.npmjs.com/~gurgunday](https://www.npmjs.com/~gurgunday)
- [**Tomas Della Vedova**](https://github.com/delvedor),
  [https://x.com/delvedor](https://x.com/delvedor), [https://www.npmjs.com/~delvedor](https://www.npmjs.com/~delvedor)
- [**Carlos Fuentes**](https://github.com/metcoder95),
  [https://x.com/metcoder95](https://x.com/metcoder95), [https://www.npmjs.com/~metcoder95](https://www.npmjs.com/~metcoder95)
- [**Vincent Le Goff**](https://github.com/zekth)
- [**Jean Michelet**](https://github.com/jean-michelet),
  [https://www.npmjs.com/~jean-michelet](https://www.npmjs.com/~jean-michelet)
- [**KaKa Ng**](https://github.com/climba03003),
  [https://www.npmjs.com/~climba03003](https://www.npmjs.com/~climba03003)
- [**Maksim Sinik**](https://github.com/fox1t),
  [https://x.com/maksimsinik](https://x.com/maksimsinik), [https://www.npmjs.com/~fox1t](https://www.npmjs.com/~fox1t)
- [**Frazer Smith**](https://github.com/Fdawgs), [https://www.npmjs.com/~fdawgs](https://www.npmjs.com/~fdawgs)
- [**Manuel Spigolon**](https://github.com/eomm),
  [https://x.com/manueomm](https://x.com/manueomm), [https://www.npmjs.com/~eomm](https://www.npmjs.com/~eomm)
- [**Antonio Tripodi**](https://github.com/Tony133), [https://www.npmjs.com/~tony133](https://www.npmjs.com/~tony133)

### Emeritus Contributors

Great contributors to a specific area of the Fastify ecosystem will be invited
to join this group by Lead Maintainers when they decide to step down from the
active contributor's group.

- [**Tommaso Allevi**](https://github.com/allevo),
  [https://x.com/allevitommaso](https://x.com/allevitommaso), [https://www.npmjs.com/~allevo](https://www.npmjs.com/~allevo)
- [**Ethan Arrowood**](https://github.com/Ethan-Arrowood/),
  [https://x.com/arrowoodtech](https://x.com/arrowoodtech), [https://www.npmjs.com/~ethan_arrowood](https://www.npmjs.com/~ethan_arrowood)
- [**Çağatay Çalı**](https://github.com/cagataycali),
  [https://x.com/cagataycali](https://x.com/cagataycali), [https://www.npmjs.com/~cagataycali](https://www.npmjs.com/~cagataycali)
- [**David Mark Clements**](https://github.com/davidmarkclements),
  [https://x.com/davidmarkclem](https://x.com/davidmarkclem),
  [https://www.npmjs.com/~davidmarkclements](https://www.npmjs.com/~davidmarkclements)
- [**dalisoft**](https://github.com/dalisoft), [https://x.com/dalisoft](https://x.com/dalisoft),
  [https://www.npmjs.com/~dalisoft](https://www.npmjs.com/~dalisoft)
- [**Dustin Deus**](https://github.com/StarpTech),
  [https://x.com/dustindeus](https://x.com/dustindeus), [https://www.npmjs.com/~starptech](https://www.npmjs.com/~starptech)
- [**Denis Fäcke**](https://github.com/SerayaEryn),
  [https://x.com/serayaeryn](https://x.com/serayaeryn), [https://www.npmjs.com/~serayaeryn](https://www.npmjs.com/~serayaeryn)
- [**Rafael Gonzaga**](https://github.com/rafaelgss),
  [https://x.com/_rafaelgss](https://x.com/_rafaelgss), [https://www.npmjs.com/~rafaelgss](https://www.npmjs.com/~rafaelgss)
- [**Trivikram Kamat**](https://github.com/trivikr),
  [https://x.com/trivikram](https://x.com/trivikram), [https://www.npmjs.com/~trivikr](https://www.npmjs.com/~trivikr)
- [**Ayoub El Khattabi**](https://github.com/AyoubElk),
  [https://x.com/ayoubelkh](https://x.com/ayoubelkh), [https://www.npmjs.com/~ayoubelk](https://www.npmjs.com/~ayoubelk)
- [**Cemre Mengu**](https://github.com/cemremengu),
  [https://x.com/cemremengu](https://x.com/cemremengu), [https://www.npmjs.com/~cemremengu](https://www.npmjs.com/~cemremengu)
- [**Salman Mitha**](https://github.com/salmanm),
  [https://www.npmjs.com/~salmanm](https://www.npmjs.com/~salmanm)
- [**Nathan Woltman**](https://github.com/nwoltman),
  [https://x.com/NathanWoltman](https://x.com/NathanWoltman), [https://www.npmjs.com/~nwoltman](https://www.npmjs.com/~nwoltman)

## Hosted by

[](https://openjsf.org/projects)

We are an [At-Large
Project](https://github.com/openjs-foundation/cross-project-council/blob/HEAD/PROJECT_PROGRESSION.md#at-large-projects)
in the [OpenJS Foundation](https://openjsf.org/).

## Sponsors

Support this project by becoming a [SPONSOR](./SPONSORS.md)!
Fastify has an [Open Collective](https://opencollective.com/fastify)
page where we accept and manage financial contributions.

## Acknowledgments

This project is kindly sponsored by:

- [NearForm](https://nearform.com)
- [Platformatic](https://platformatic.dev)

Past Sponsors:

- [LetzDoIt](https://www.letzdoitapp.com/)

This list includes all companies that support one or more team members
in maintaining this project.

## License

Licensed under [MIT](./LICENSE).

For your convenience, here is a list of all the licenses of our production
dependencies:

- MIT
- ISC
- BSD-3-Clause
- BSD-2-Clause
