Node DDD API Example
To see how works
First of all, create the .env file (you have the example of the .env.example file).
After starting the docker services, be sure to install the dependencies and if you want, you can run the migration to have the database structure and two registered users.
Commands
Start docker services
make upor
docker-compose up -dThis will start the Node and PostgreSQL docker services.
If have error be sure that your local services (like postgreSQL) are stopped.
Down docker services
make downor
docker-compose downRun project
make run-devor
docker-compose exec api npm run devThis will run nodemon with typescript in dev environment.
Run project compile
make run-startor
docker-compose exec api npm run startThis will compile typescript in ./dist folder and run nodemon with js transpiled.
Build project
make run-buildor
docker-compose exec api npm run buildThis will only compile the typscript
Install dependencies
make installor
docker-compose exec api npm installRun eslint
make eslint-check
make eslint-fixor
docker-compose exec api npm run eslint:check
docker-compose exec api npm run eslint:fixRules for eslint are in .eslintrc.json file on root path.
Run unit test
make run-test-unitor
docker-compose exec api npm run test:unitRun coverage for unit test
make run-test-unit-coverageor
docker-compose exec api npm run test:unit:coverageMigrations
Run migrations up
make migrate-backoffice-runor
docker-compose exec api npm run migrate:backoffice:runRun migrations down
make migrate-backoffice-revertor
docker-compose exec api npm run migrate:backoffice:revertCreate migrations
docker-compose exec api npx db-migrate create {name_of_migration}Endpoints
Get all users on backoffice
Request
Method:
GET
Response
[
{
"id": "32547dd7-617a-4985-a59a-91a176e55b83",
"name": "Iván"
},
{
"id": "43ba0b24-4d0b-40f7-aa7f-1b2a3058f484",
"name": "Nabby"
}
]Get one user on backoffice
Request
Method:
GET
URL: http://localhost:8080/backoffice/users/32547dd7-617a-4985-a59a-91a176e55b83
Response
{
"id": "32547dd7-617a-4985-a59a-91a176e55b83",
"name": "Iván"
}Create user on backoffice
Request
Method:
POST
Body:
{
"name": "Iván"
}Response
No response
Update user on backoffice
Request
Method:
PUT
URL: http://localhost:8080/backoffice/users/32547dd7-617a-4985-a59a-91a176e55b83
Body:
{
"id": "32547dd7-617a-4985-a59a-91a176e55b83",
"name": "Other"
}Response
No response
Delete user on backoffice
Request
Method:
DELETE
URL: http://localhost:8080/backoffice/users/32547dd7-617a-4985-a59a-91a176e55b83
Response
No response