Learning NodeJs with Fastify Framework

Fastify is creating its space in NodeJs community. This boilerplate has advance features to setup an application with bare minimum customization.

Danish Siddiq
tajawal
2 min readFeb 16, 2020

--

Fastify claims to be more efficient than Express, I do not go into this debate, but I use and like both of them.

As of now, Fastify framework is already popular in NodeJs community, and it claims to process 30,000 requests per seconds. The framework contains many features like logging, detailing request and response schema on routes, validations, hooks to perform before and after operations on specific events, and more features without depending on external packages. Following is the link to the repository:

Although it’s pretty easy to understand the framework by running this boilerplate, and calling endpoints mentioned in the “ReadMe” file, It is better to have some prior knowledge of NodeJs .

Boilerplate Features:

  1. Server setup.
  2. MongoDb connection.
  3. RabbitMQ connection.
  4. Logging mechanism.
  5. Routes for modules and application health.
  6. Middleware.
  7. Controllers.
  8. Services directory for business requirements implementation.
  9. Database basic operations implementation.
  10. Jest for API’s testing.
  11. Configuration file for different environments.
  12. Error details consistency.

Features Details:

A little more detail for few important components included in the boilerplate:

  1. RabbitMQ producer and consumer logic along with auto connectivity feature in case of any disruption with the RabbitMQ connection. Currently, code for setting-up a connection is commented in the “app.js” file.
  2. Schema definition for each request and response expected from the route. Schema is shareable with clients’ in JSON format but a better approach is to define a schema in a separate package. In case of updates, client can pull package updates more efficiently.
  3. Info or health routes to know application and components status.
  4. Repository module to perform database operations, it avoids code clutter in model.
  5. .config and .override.config files to define application configuration in different environments. This can also be handled by using packages.
  6. Jest is used for testing API’s.

This boilerplate helps to focus on business requirements implementation instead of investing time in a project setup. Feel free to improve it.

One more time sharing link to the repository:

--

--