Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/lissone/node-fastify-knex

Simple Node Fastify API using Knex with SQLite and tests.
https://github.com/lissone/node-fastify-knex

eslint fastify knex nodejs sqlite3 supertest typescript vitest zod

Last synced: about 1 month ago
JSON representation

Simple Node Fastify API using Knex with SQLite and tests.

Awesome Lists containing this project

README

        


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

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

### Business Rules

- [x] The transaction can be of the credit type, which will add to the total amount, or debit, which will subtract;
- [x] It must be possible to identify the user among the requests;
- [x] 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

- [Npm](https://www.npmjs.com/)
- [Yarn](https://yarnpkg.com/)
- [Nodejs](https://nodejs.org/en/)

## 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:

```bash
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:

```bash
npm run knex -- migrate:latest
```

About more knex commands:

```bash
# List knex help
npm run knex -- -help
# Create a migration
npm run knex -- migrate:make
```

### Add environment variables

```bash
# .\.env

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

### Install dependencies

```bash
yarn
#or
npm install
```

### Run project

```bash
yarn start:dev
#or
npm run start:dev
```

## License

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