This is my personal implementation of the app be-the-hero from the omnistack 11 make by rocketseat.
Statements | Branches | Functions | Lines |
---|---|---|---|
Here is a link to the project docs.
Here is a link to the api docs.
Node current LTS
To install node
and npm
just download it here or follow this tutorial.
To check the version run the command
$ node -v
v12.16.1
Yarn version 1.22.4 or npm (latest is advised)
To install yarn
just follow their docs
To check the version run the command
$ yarn -v
1.22.4
Postgres version 12.2
Docker and docker-compose
$ docker -v
Docker version 19.03.8, build afacb8b7f0
$ docker-compose -v
docker-compose version 1.25.4, build 8d51620a
- Install
yarn
ornpm
- Install the
postgres
dbms in your machine OR docker (composer is also optional)
If you want to execute the knex
commands with a shorter command, just install the npx
module
globaly.
So you'll be able to run
$ npx knex command
Instead of
$ node_modules/.bin/knex command
-
Clone the repository and enter the repository directory
$ git clone [email protected]:rafaelcascalho/be-the-hero-backend.git $ cd be-the-hero-backend
-
Set up the database
- Run the postgres server
- Create a database with a name of your choice
- Create a
.env
file based on the.env.example
file, and fill it with your database information - Install the project dependencies with one of the commands below
$ yarn install
-
After that, we need to run the migrations with the following command
$ node_modules/.bin/knex migrate:latest
To check if your migrations were successfull just run the command
$ node_modules/.bin/knex migrate:status
And you should see and outcome like this one
Found 2 Completed Migration file/files. 20200328191618_create_ongs.js 20200328192842_create_incidents.js No Pending Migration files Found.
-
After that's done, you can just check if your
development
environment is running using the command$ yarn dev
-
That's it! You're all set. :clinking_beer_mugs:
To seed the database just run the command
$ yarn seed
To run the tests just use the command
$ yarn test
To run the tests and generate the coverage report run the command
$ yarn test:cov
To check if your dependecies have vulnerabilities just run the command
$ yarn sec
Case snyk finds any problems, you can run the wizard to manage them one by one with the command
$ yarn sec:wizard
To access the coverage reports generated, you can just access the /coverage/lcov-report/index.html
from your browser, in the just generated folder coverage
in the root of the project.
This project is currently deployed at heroku PAAS. Case you're interested in doing the same just check out this tutorial.
This is an example of my docker-compose file
version: "3"
services:
psql:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: password
volumes: - ./data:/var/lib/postgresql/data
ports: - 5455:5432
- NodeJs - Backend environment for javascript
- Knex - SQL query builder
- Celebrate - Request validator
- Dotenv - Env files loader
- Winston - Logger
- Cors - Cors enabler for express
- Jest - Automated tests library
- Chance - Random data generator for tests
- PM2 - Process manager for deployment
- Snyk - Dependency security checker
- Helmet - Headers setter for security for express
- Eslint - Code linting tool
- Prettier - Code formatter
- Editorconfig - Code style enforcer
- Docker - Virtualizer of containers
- Docker Compose - Containers manager
- Postgres - Database