Node DDD API Example
Commands
Start docker services
docker-compose up -dThis will start the Node and PostgreSQL docker services.
If haver error be sure that your local services are stopped.
Down docker services
docker-compose downRun project
docker-compose exec app npm run devThis will run nodemon with typescript in dev environment.
Run project compile
docker-compose exec app npm run startThis will compile typescript in ./dist folder and run nodemon with js transpiled.
Build project
docker-compose exec app npm run buildThis will only compile the typscript
Run tslint
docker-compose exec app npm run tslintThis will execute tslint to standard code.
Run unit test
docker-compose exec app npm run test:unitThis will execute unit tests
Migrations
Run migrations up
docker-compose exec app npm run migrate:upRun migrations down
docker-compose exec app npm run migrate:downCreate migrations
docker-compose exec app npx db-migrate create {name_of_migration}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 and the application node make sure to run the migration up to have the database structure and two users record.
Endpoints
Get all users
Request
Method:
GET
Response
[
{
"id": "32547dd7-617a-4985-a59a-91a176e55b83",
"name": "Iván"
},
{
"id": "43ba0b24-4d0b-40f7-aa7f-1b2a3058f484",
"name": "Nabby"
},
]Get one users
Request
Method:
GET
URL: http://localhsot:8080/users/32547dd7-617a-4985-a59a-91a176e55b83
Response
{
"id": "32547dd7-617a-4985-a59a-91a176e55b83",
"name": "Iván"
}Create user
Request
Method:
POST
URL: http://localhsot:8080/users/32547dd7-617a-4985-a59a-91a176e55b83
Body:
{
"name": "Iván"
}Response
No response
Update user
Request
Method:
PUT
URL: http://localhsot:8080/users/32547dd7-617a-4985-a59a-91a176e55b83
Body:
{
"name": "Other"
}Response
No response
Delete user
Request
Method:
DELETE
URL: http://localhsot:8080/users/32547dd7-617a-4985-a59a-91a176e55b83
Response
No response