/node-fastify-knex

Simple Node Fastify API using Knex with SQLite and tests.

Primary LanguageTypeScript

Simple Node Fastify API using Knex

Description   |    Requirements   |    Technologies   |    Usage


License Repo size Top lang Stars repo Forks repo Pull requests Last commit

Report bug · Request feature


Description

This project was developed with the goal of exploring and learning how to use the Fastify library for creating APIs with Node.js, as well as getting familiar with Knex as a query builder to interact with databases. I also took the opportunity to practice and solidify my knowledge in testing.

Functional Requirements

  • The user must be able to create a new transaction;
  • The user must be able to get a summary of their account;
  • The user must be able to list all transactions that have occurred;
  • The user must be able to view a single transaction.

Business Rules

  • The transaction can be of the credit type, which will add to the total amount, or debit, which will subtract;
  • It must be possible to identify the user among the requests;
  • The user can only view transactions they have created.

About Tests

  • Unit: unit of your application;
  • Integration: communication between two or more units;
  • E2E: simulate a user operating in our application.

Test pyramid: E2E does not depend on any technology, nor on architecture.

Requirements

Technologies

  • Nodejs
  • Typescript
  • Fastify
  • Knex
  • Sqlite3
  • Zod
  • Vitest
  • Supertest
  • Eslint
    • @rockeseat/eslint-config
  • Prettier

Usage

You can clone it on your pc using the command:

git clone https://github.com/Lissone/node-fastify-knex.git
cd node-fastify-knex

Run migrations

You need to run a knex script command to run all current migrations:

npm run knex -- migrate:latest

About more knex commands:

# List knex help
npm run knex -- -help
# Create a migration
npm run knex -- migrate:make <name_migration>

Add environment variables

# .\.env

NODE_ENV=development
DATABASE_URL="./db/app.db"

Install dependencies

yarn
#or
npm install

Run project

yarn start:dev
#or
npm run start:dev

License

Distributed under the MIT License. See LICENSE for more information.