Fast and low overhead web framework, for Node.js

Why

An efficient server implies a lower cost of the infrastructure, a 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 as possible, without sacrificing security validations and handy development?

Enter Fastify. Fastify is a web framework highly focused on speed and low overhead. It is inspired from Hapi and Express and as far as we know, it is one of the fastest web frameworks in town. Use Fastify can increase your throughput up to 100%.

Quick start

Get fastify with NPM:

npm install fastify

Then create server.js and add the following content:

'use strict'

const fastify = require('fastify')()

const schema = {
  schema: {
    response: {
      200: {
        type: 'object',
        properties: {
          hello: {
            type: 'string'
          }
        }
      }
    }
  }
}

fastify
  .get('/', schema, function (req, reply) {
    reply
      .send({ hello: 'world' })
  })

fastify.listen(3000, err => {
  if (err) throw err
  console.log(`server listening on ${fastify.server.address().port}`)
})

Finally, launch the server with:

node server

and you can test it with:

curl http://localhost:3000

Visit the Documentation to learn more about fastify.

Core features

These are the main features and principles on which fastify has been built:

  • 100% asynchronous: all the core is implemented with asynchronous code, in this way not even a millisecond is wasted.
  • 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 20000 request per second.
  • Extendible: Fastify is fully extensible via its hooks, plugins and decorators.
  • Schema based: even if it is not mandatory we recommend to use JSON Schema to validate your routes and serialize your outputs, internally Fastify compiles the schema in an highly performant function.
  • Logging: logs are extremely important but are costly; we chose the best logger to almost remove this cost, Pino!
  • Developer friendly: the framework is built to be very expressive and help the developer in his daily use, without sacrificing performance and security.

A faster web framework

Leveraging our experience with Node.js performance, Fastify has been built from the ground up to be faster than the currently well-known web frameworks such as Express or Hapi. Have a look at our benchmarks section to compare fastify performance to other common web frameworks.

~6 times
faster than HAPI

~1.5
faster than Express

Ecosystem

Fastify has an ever-growing ecosystem of plugins. Probably there is already a plugin for your favourite database or template language. Have a look at the Ecosystem page to navigate through the currently available plugins. Can't you find the plugin you are looking for? No problem, it's very easy to write one!

38
Plugins

The team

In alphabetical order

Lead Maintainers

Matteo Collina's profile picture

Matteo Collina

github npm twitter

Tomas Della Vedova's profile picture

Tomas Della Vedova

github npm twitter

Collaborators

Dustin Deus's profile picture

Dustin Deus

github npm twitter

Evan Shortiss's profile picture

Evan Shortiss

github npm twitter

James Sumners's profile picture

James Sumners

github npm twitter

Luciano Mammino's profile picture

Luciano Mammino

github npm twitter

Tommaso Allevi's profile picture

Tommaso Allevi

github npm twitter

Çağatay Çalı's profile picture

Çağatay Çalı

github npm twitter

Acknowlegments

This project is kindly sponsored by:

Also thanks to: