Install NodeJS LTS version higher than 16 from: https://nodejs.org/
Use git clone .....
in your terminal to clone the project.
Remember to add the .env
file in the root of project with the environment variables. You can use .env.example
as a template.
You need to run this command in your terminal at the root of project. This will install all its dependencies using:
npm install
Note: the dependencies of the project are in package.json
file.
We have some util scripts in package.json
file:
Script | Description | Notes | ||
---|---|---|---|---|
npm run start:dev |
Run and start the project | |||
npm run migration:generate name-of-migration |
Generate a migration with the name that you provide | If you modified or created an entity, the migration will be generated with the queries to make the changes in the database | ||
npm run migration:up |
Run the pending migrations | This will generate a migration at the root of project. You need to move to src/database/migrations | ||
npm run migration:down |
Revert the migrations | |||
npm run seed:run |
Run seeds to get fake data in database | The seeds are in src/database/seeds | ||
npm run seed:config |
Return the config of seeds | The config of seeds is in ormconfig.json file | ||
npm run test |
Run tests | |||
npm run lint |
Run linter to check the format of the code | Some rules are in tslint.json |
The project works with TypeScript, TypeORM (as ORM), Jest (for tests) and ExpressJS (as the router).
The source of project is in src
folder. So, The project starts in server.ts
file, that uses app.ts
. This files are separated because we need to have only the server for Jest configuration.
In this source code, you can see some folders. Below is a brief description of them:
- Database: This folder contains the
dataSource.ts
file that allows the connection with the database. Also, contains some folders that have to do with database. Themigrations
folder contains the changes in the database (inserts, deletes, new tables, etc.) and you can create and do some things with them with the scripts that are inpackage.json
. Theentities
folder contains the model of each entity. Thefactories
folder contains the factories that are used inseeds
folder. - Exceptions: Contains all exceptions that the API can return.
- Middleware: Contains the validation middlewares.
- Controllers: Contains controllers of the endpoints.
- Interfaces: Contains the interfaces of the project. Here we can put de DTO's (
mappers
andserializers
).
When you add a new environment variable, you need to add it also in the validation file of env vars validateEnv.ts
and in the drive of the project.