- Read the rest of this README.md
- Follow the
Start project
section - Run the tests
- Start the server
After all is setup & running, feel free to remove the local git repository and initialize a new one, rename databases, and remove the sample source code.
This section is going to show a curated list of the packages and tools used for this project (to see
the full list of dependencies take a look at package.json
)
- Koa
- Koa Router
- Koa CORS
- Koa Passport
- Koa Bodyparser
- Objection.js
- knex
- Jest
- PostgreSQL
- Docker
- Docker Compose
- Git
In order to start the project with docker you just need to execute the following script (you should have docker already installed and working on your machine)
./bin/start
The script assumes that you have a .env.sample
file that file is going to be copied to a file
with the name .env
and it's going to be used to start the application
The following files needs to be copied and modified accordingly
$ cp .env.sample .env
After copy those files edit them to have the right values (ask a teammate if you don't know any of those values), then you will need to create the database to do Postres is required to be up and running (if you have it you can avoid the installation instructions for Postgres)
The easiest way to install postres is using this app, just follow the instructions on their site and you will be ready to go (you might need to reload the terminal to have access to postgres app commands)
To install all the tools required by the project you need a tool to manage the version of
the tools. Using asdf-vm
you can install all the tools, to install it you need to
follow the instructions on https://asdf-vm.com/
If you want to manage node versions using asdf you need to install a plugin that is able to install the different node versions, to do that just type the following command
$ asdf plugin add nodejs
And then to install nodejs run the following command
$ asdf install nodejs 16.10.0
$ yarn install
Based on the information on the file .env
(that you copy previously) create two
databases on for test
and one for development
to do that just run the following command
$ createdb node_template_development
$ createdb node_template_test
Make sure those names matches what you have on .env
$ yarn run dev
This command will start a dev server and every change that is made to the code is reflected on the terminal, that is running the code.
By default it will start the server port 3000. If you want to run the server in a different port, update the PORT environment variable
If you are running the project with docker, first you need to enter to the terminal (inside the container), to do that just type the following command on your shell:
$ ./bin/terminal
Once you are there you can use the following commands to either migrate or seed the database, for none docker users just type the commands directly on the root of the project.
In order to have the latest schema on your database you need to run the following command:
$ yarn migrate:latest
Then to create some seed data for development the following command can be run:
$ npx knex seed:run
- To generate an entity scaffold:
npx hygen generate scaffold
- Make migration:
npx hygen generate migration
- Make seed:
npx hygen generate seed
To run the test just type the following command
$ yarn run test
To run the linter and fix try to fix issues automatically run the following command
$ yarn run lint -- --fix
The template has some example files like models, migrations, and tests for those models once you are comfortable with the template you can execute the following script to clean up the template:
$ ./bin/cleanup