Skip to content

Pedroglp/fastify-template

Repository files navigation

Fastify Template

Purpouse

This project means to be a fastify template for starting applications quickly. At the moment it only supports MongoDB as database. You can switch between branches to get other examples, such as authentication in auth-example branch.

This project uses docker to start the enviroment, you can check the docker enviroment configuration at:

  • Dockerfile
  • docker-compose-.yml

Setup

Since the project uses docker and docker-compose, you first need to install those two. There are a lot of guides at web and the setup will be different depending on your OS. Check at:

Then, clone or degit

git clone https://github.com/Pedroglp/fastify-template/tree/develop
degit https://github.com/Pedroglp/fastify-template/tree/develop my-project/

The differene between gitclone and degit is that degit doesn't link your application to any git remote project.

Also, you need to have node if you wish to run in development mode:

Starting

At the moment, you can start the application in 2 different modes:

  • Stage - Uses docker to starting the application and database.
npm run stage
  • Development - It only uses docker to start MongoDB, so it's faster for testing.
npm run dev

WARNING: The implementation of docker enviroment its not the best of the world, you can see that the server will fail multiple times until it get started. This is because the database hasn't finsihed starting, the solution for this problem is here.

Project Structure

api

This is where the magic happens. This folder has a set of others folder that are usually used when implementing your API: handlers, helpers, hooks and schemas. The only file inside is routes.js, this file is responsable to specify your routes for then be connected at fastify using routes-connector, you are not obligated to use it and you can still initialize routes using fastify.get()/post() (...).

config

This is where you should put your configurations and specific connectors, but be free if you want to change it. Inside config there is the env path, where you should put your specific configuration for each application. Also, there are two connectors: routes-connector and schemas-connector, they are not necessary and you can remove them.

start.js

Here is where you generally imports your plugins, routes and initialize the application.

About

Basic fastify template for resftul services

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published