ESM Api structure
- Installation
- How to run tests
- Concept of Project Structure
- Hooks
- Dependencies of project
- Dev Dependencies of project
This is a Node.js module available through the
npm registry. It can be installed using the
npm
or
yarn
command line tools.
npm install
npm run test
├── app.js
├── data
│ ├── connections
│ ├── README.md
│ ├── repositories
│ └── structures
├── domain
│ └── README.md
├── handlers
│ ├── home.js
│ └── README.md
├── index.js
├── middlewares
│ ├── global
│ │ ├── dependencyInjection.js
│ │ ├── README.md
│ │ └── responseApi.js
│ └── README.md
├── routes
│ ├── README.md
│ └── routes.js
├── services
│ └── README.md
└── utils
└── README.md
The data folder contains all point of access to external data, like Database, Repositories or any other source of dataaccess
The data folder can the following sub folders:
- Repositories // Abstraction of connection data
- Connection // The raw connections like PostgreSQL, MongoDB etc...
- Structures // Abstraction of model of data
A sphere of knowledge (ontology), influence, or activity. The subject area to which the user applies a program is the domain of the software
The handlers folder contains all of the handlers of requests ( Similar to the Controller in MVC Pattern ) and he has the following responsibilities:
- Validation of data (
JOI
by default) - Delegate response to the requested resource ( Like
BO
,DOMAIN
,SERVICES
) - Catch all exceptions and treat them ( Using
rescue
in these cases)
The middlewares folder follows the globally known pattern. Any checks or treatments take place on that layer, something like:
- Check if user is authenticated to enter in requested route. (
isAuth
) - Check if user authenticated has access to requested resource (
role
)
The global folder inside middleware, means that they are global and commons middlewares
on all routes
The routes.js
contains all register of routes, and they has the following responsibility:
- Register routes and method ( GET| POST| PUT| DELETE| PATCH )
- Register middleware to route that needs them
- Delegate the response to the last middleware (
handler
)
The services folder can be used to delegate responsibility to each functionality of software
Are the simplest functions that will help you in your business rule
Hooks are routines that runs automatically after a event
Has the follow scripts hooks registered
- postinstall - After
npm install
generate .env file if not exists
Has the follow git hooks registered
- git commit - After
git commit
runsnpm run lint
andnpm run test
if no error, continue
- dotenv: Loads environment variables from .env file
- express: Fast, unopinionated, minimalist web framework
- express-rescue: A wrapper for async functions which makes sure all async errors are passed to your errors handler
- eslint: An AST-based pattern checker for JavaScript.
- eslint-config-standard: JavaScript Standard Style - ESLint Shareable Config
- eslint-plugin-import: Import with sanity.
- eslint-plugin-node: Additional ESLint's rules for Node.js
- eslint-plugin-promise: Enforce best practices for JavaScript promises
- eslint-plugin-standard: ESlint Plugin for the Standard Linter
- nodemon: Simple monitor script for use during development of a node.js app.