EN - English (Versão em Português Brasil aqui)
Project developed during the back-end module of the Trybe full-stack web development course.
In this project an API and a database were developed to produce content for a blog.
A Node.js application using the sequelize package to do a CRUD of posts. Creating endpoints that are connected to the database following REST principles
- ✅EndPoint for user login, using the POST method.
- ✅EndPoint for registering users, using the POST method.
- ✅EndPoint for lists all registered users, using the GET method
- ✅EndPoint for lists by id only a registered user, using the GET method
- ✅EndPoint to delete logged in user, using the DELETE method
- ✅EndPoint for post category registration, using the POST method.
- ✅EndPoint for lists all categories of registered posts, using the GET method
- ✅EndPoint for lists all registered posts, using the GET method
- ✅EndPoint for lists by id just a registered post, using the GET method
- ✅EndPoint for lists by query informed only a registered post that corresponds to the title or content of the post, using the GET method
- ✅EndPoint for registering a new post, using the POST method.
- ✅EndPoint to update an existing post, using the PUT method.
- ✅EndPoint to delete an existing post, using the DELETE method
- ✅To make a post, you need a user and a login, so the relationship between the user and post tables is worked on
- ✅It is necessary to use categories for posts, thus working on the relationship between posts tables for categories and categories for posts
🐋 Running on Docker vs Locally
1.26.0
with 1.29.2
.
ℹ️ Run the
node
anddb
services with thedocker-compose up -d --build
command.
-
Remember to stop
mysql
if you are using it locally on the default port (3306
), or adapt it, if you want to use the application in containers; -
These services will initialize a container named
blogs_api
and another namedblogs_api_db
; -
From here you can run the
blogs_api
container via CLI or open it in VS Code;
ℹ️ Use the command
docker exec -it blogs_api bash
.
- It will give you access to the interactive terminal of the container created by compose, which is running in the background.
ℹ️ Install dependencies [If any] with
npm install
. (Install inside the container)
-
⚠️ Attention: If you choose to use Docker, ALL the commands available inpackage.json
(npm start, npm test, npm run dev, ...) must be executed **INSIDE ** of the container, that is, in the terminal that appears after executing thedocker exec
command mentioned above. -
⚠️ Attention: The git inside the container is not configured with your credentials. Either commit outside the container, or set your git credentials inside the container. -
⚠️ Attention: Do not run the npm audit fix command! It updates several project dependencies, and this update causes conflicts. -
✨ Tip: The
Remote - Containers
extension is indicated so that you can develop your application in the Docker container directly in VS Code, as you do with your local files.

ℹ️ Install dependencies [If any] with
npm install
-
⚠️ Attention: Do not run the npm audit fix command! It updates several project dependencies, and this update causes conflicts. -
✨ Tip: To run the project this way, you must have
node
installed on your computer.
🎲 ER and Entities Diagram
-
A table called users, containing data with the following structure:
id display_name email password image 1 Brett Wiltshire [email protected] // tem quer ser único 123456 http://4.bp.blogspot.com/_YA50adQ-7vQ/S1gfR_6ufpI/AAAAAAAAAAk/1ErJGgRWZDg/S45/brett.png -
A table called categories, containing data with the following structure:
id name 18 News -
A table called blog_posts, containing data with the following structure:
id title content user_id published updated 21 Latest updates, August 1st The whole text for the blog post goes here in this key 14 // Foreign key, referencing the id of users
2011-08-01T19:58:00.000Z 2011-08-01T19:58:51.947Z -
A table called PostCategories, containing a composite primary key using the two structure attributes:
post_id category_id 50 // Primary and foreign key, referencing the id of BlogPosts
20 // Primary and foreign key, referencing id from Categories
The data above are fictitious, and are here only as an example
👀 Ready-made script tips
-
Delete the database:
"drop": "npx sequelize-cli db:drop"
-
Create the database and generate the tables:
"prestart": "npx sequelize-cli db:create && npx sequelize-cli db:migrate"
-
Insert data / Populate the table:
"seed": "npx sequelize-cli db:seed:all"