Building web applications with Fastify
Fastify is a web framework inspired by other popular Node.js web frameworks, including Hapi and Express.js. As the name may suggest, Fastify focuses on minimizing performance overhead, but the framework also has developer experience in mind.
While Fastify can be used to create web applications, it really excels when you're building JSON-based APIs. In the recipe, we'll create a JSON-based API.
Getting ready
First, let's create a directory named fastify-app
to hold our project. As we'll be using modules from npm, we'll also need to initialize a new project as follows:
$ mkdir fastify-app $ cd fastify-app $ npm init --yes
Now that we've initialized our project directory, we can move on to the recipe.
How to do it
In this recipe, we will create a web server with Fastify that responds on the /
route with some JSON data:
- Start by installing
fastify
:$ npm install fastify
- Next, we'll...