This is a project to practice Node.js, typescript and docker compose.
This project it's possible create, update, list and delete posts.
- fastify
- typeorm
- date-fns
- dotenv
- jest
- mysql
- typescript
- docker
- docker-compose
- Need to have docker installed.
- Need to have docker-compose installed.
To setup project follow these steps ahead.
Create a .env
file at root directory, there's a .env.example
to be used as a draft and model.
MYSQL_DATABASE=[MYSQL_DATABASE]
MYSQL_USER=[MYSQL_USER]
MYSQL_PASSWORD=[MYSQL_PASSWORD]
MYSQL_ROOT_PASSWORD=[MYSQL_ROOT_PASSWORD]
MYSQL_PORT=[MYSQL_PORT]
# MYSQL_HOST there's no need to fill, this variable is provided by docker compose setup
MYSQL_HOST=[MYSQL_HOST]
NODE_POSTS_API_PORT=[NODE_POSTS_API_PORT]
NODE_APP_HOST=[NODE_APP_HOST]
NODE_ENV=[NODE_ENV]
$ docker-compose up -d
- API will be available at host
localhost
and port[NODE_POSTS_API_PORT
.
- Create a new post
POST http://localhost:[NODE_POSTS_API_PORT]/posts
BODY {
content: string,
author: string
}
- Get post
GET http://localhost:[NODE_POSTS_API_PORT]/posts/:id
- Get posts
GET http://localhost:[NODE_POSTS_API_PORT]/posts
QUERY {
page: number,
limit: number,
}
- Update post
PATCH http://localhost:[NODE_POSTS_API_PORT]/posts/:id
BODY {
content: string,
author: string
}
- Delete a post
DELETE http://localhost:[NODE_POSTS_API_PORT]/posts/:id
BODY {}
- Database structure:
Table posts
Fields
id
content
author
status
created_at
updated_at
An application to see database it's needed, host to connect it's localhost
and port it's [MYSQL_PORT]
.
- Credentials:
MYSQL_USER=[MYSQL_USER]
MYSQL_PASSWORD=[MYSQL_PASSWORD]
MYSQL_ROOT_PASSWORD=[MYSQL_ROOT_PASSWORD]
to access as a root user use root user and [MYSQL_ROOT_PASSWORD]
$ docker-compose down
$ docker-compose down --rmi all
Run this commands
$ docker-compose down
$ docker-compose build
$ docker-compose up -d
$ npm run test
To run unit tests$ npm start
To run application$ npm run build
To build application$ npm run dev
To run in dev mode watching changes