Propose the base of an app architecture for an API REST with CRUD (Create, Read, Update, Delete) routes.
This app implements various strong and usefull tools to help :
- Back developer to build the API
- Front developer to use the API
To keep clean and beautiful code, this app propose some NPMs (Node Package Module) in dev dependencies
- ESLlint file that extends the airbnb config which is one of the most popular
- Prettier file to formate the code
- EditorConfig file to help to maintain consistent coding rules across various IDE (integrated development environment)
To have better logs in console and keep some logs saved in log files
- debug provides better console logs and allow to toggle the logs for differents parts of the modules
- bunyan allow to save some logs in JSON
To validate the data format
- joi allow to describe data in schemas, and validate the compliance of the data sent.
In the helpers
folder, controllerHandler.js
is used with each route which needs async/await. It wraps all the called controllers in a try/catch that allows to lighten the code without include all async/await in try/catch everywhere.
A csutom class named ApiError
is available to get errors with status code and to throw custom error, with custom message and code.
2 SQL scripts are provided to create an example database which works with this base app
create_tables_example.sql
for the DDL (Data Definition Language)seeding_example.sql
for the DML (Data Manipulation Language)
pug homepage with link to doc