Skip to content

lucaspalencia/node-api-pg

Repository files navigation

Node API with PostgreSQL

To do list application example using Node.js API starter with PostgreSQL

Requirements

To run this project you need to have installed:

Setup

Prepare your development environment

Create a copy .env file from .env.example and populate the variables.

Install dependencies:

make install

Run migrations:

make migrate-up

Start application:

make up

View logs:

make logs

This command will boot:

  • Node API on http://localhost:3000 if PORT variable has not been set on .env file. If variable has been set, will boot API on http://localhost:${PORT}

  • PostgreSQL database on PORT 5432 with environments variables defined in docker-compose.yml. To change database name, just change it in both docker-compose.yml and .env files

Users module

Folder: /src/users

Create user

POST to /users endpoint with request body such as:

{
  "name": "User name",
  "email": "user_email@email.com"
}

List users

GET to /users endpoint will return all users on database

Tasks module

Folder: /src/tasks

Create task for a user

POST to /users/${USER_ID}/tasks endpoint with request body such as:

{
  "title": "Task tittle",
  "description": "Task description",
  "status": ["to_do", "in_progress", "on_review", "ready_for_release", "done"],
  "dueDate": "2021-05-20T18:00:00.000Z"
}

Update task

PUT to /tasks/${TASK_ID} endpoint with request body such as:

{
  "title": "Task tittle",
  "description": "Task description",
  "status": ["to_do", "in_progress", "on_review", "ready_for_release", "done"],
  "dueDate": "2021-05-20T18:00:00.000Z"
}

List user tasks

GET to /users/${USER_ID}/tasks endpoint will return user tasks

Migrations

For new migrations, just add them on migrations folder with file name as time_action_entity_type. For example: 20210517211000_create_users_table.ts

Run migrations:

make migrate-up

Rollback migrations

make migrate-down

Commands

make install                  - install dependencies
make add lib=PACKAGE_NAME     - add dependency
make add-dev lib=PACKAGE_NAME - add dev dependency
make up                       - start app
make logs                     - view logs
make down                     - kill app
make lint                     - run lint
make test                     - run tests
make test-watch               - run tests on watch mode
make test-coverage            - run tests with coverage report on /coverage folder
make build                    - build app on /dist folder
make up-build                 - start built app
make migrate-up               - run migrations
make migrate-down             - rollback the last batch of migrations
make shell                    - run app shell

Coding

About

To do list application using Node.js API starter with PostgreSQL

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages