Backend module
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
GoBarber is an application that aims to facilite the connection between barbers and clients. This repository contains the backend module and was developed during the Rocketseat Gostack bootcamp.
Main technologies, libraries and CLI tools used to built the API:
- Node.js: Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine;
- PostgreSQL: a powerful, open source object-relational database system with over 30 years of active development that has earned it a strong reputation for reliability, feature robustness, and performance;
- Redis: Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker;
- MongoDB: A document-based NoSQL database;
- Docker: Docker containers wrap up software and its dependencies into a standardized unit for software development that includes everything it needs to run: code, runtime, system tools and libraries. This guarantees that your application will always run the same and makes collaboration as simple as sharing a container image;
- node.bcrypt.js: A simple, fast, robust job/task queue for Node.js, backed by Redis;
- Bee queue: A simple, fast, robust job/task queue for Node.js, backed by Redis;
- Date-fns: Modern JavaScript date utility library;
- Express: Fast, unopinionated, minimalist web framework for node;
- jsonwebtoken: An implementation of JSON Web Tokens;
- Mongoose: MongoDB object modeling designed to work in an asynchronous environment;
- Multer: Node.js middleware for handling
multipart/form-data
; - Nodemailer: Send e-mails with Node.JS – easy as cake!
- Sequelize: An easy-to-use multi SQL dialect ORM for Node.js
To manage the code style and formatting:
To get a local copy up and running follow these steps.
-
Install Node.js: Follow the official tutorial
-
Install a package manager for node:
-
Yarn: Check yarn tutorial (Yarn 1.x (classic) was used in this project).
or
-
npm (comes with Node.js):
npm install npm@latest -g
-
-
Install Docker: Follow the official tutorial.
To install the project there are two alternatives:
- Using Docker Compose;
- Creating Docker containers manually.
-
Clone the repository and navigate to the project directory:
Using ssh: git clone git@github.com:dzvid/gobarber-api.git cd gobarber-api Or using https: git clone https://github.com/dzvid/gobarber-api.git cd gobarber-api
-
Create the
.env
file for the environment variables values of the application. You can use the.env.example
as a template:cp .env.example .env
Edit the file and set the values for the mailing service, relational and non-relational database services and Sentry token.
For the mailing service you can use Mailtrap to create a email for development and testing purposes.
For the Sentry DSN token its necessary to create an account in Sentry and follow the instructions to generate it.
Make sure the values were declared because they are used in the
docker-compose.yml
file to create the containers. -
Create and start the containers using Composer. Open a terminal window and run the following command:
docker-compose up
-
Run sequelize migrations to create the PostgreSQL database tables:
yarn sequelize db:migrate
-
At this moment the GoBarber API service runs at:
http://localhost:3333
-
You are done with configuration! I hope everything is alright and you are ready to code! 🎉
-
Create Docker containers, run the following commands in a terminal (feel free to change the container names and passwords as you wish):
-
Create PostgreSQL container:
docker run --name gobarber -e POSTGRES_PASSWORD=gobarberdev -p 5432:5432 -d --restart always postgres
-
Create MongoDB container:
docker run --name mongo_gobarber -p 27017:27017 -d -t --restart always mongo
-
Create Redis container:
docker run --name redis_gobarber -p 6379:6379 -d -t --restart always redis:alpine
-
-
Create GoBarber database in PostgreSQL:
# Open PostgreSQL container terminal docker exec -it gobarber /bin/sh # Change to postgres user su postgres # Enter postgres CLI psql # Create the database CREATE DATABASE gobarber; # Check if the database was created, run: \list
-
Clone the repository:
Using ssh: git clone git@github.com:dzvid/gobarber-api.git Or using https: git clone https://github.com/dzvid/gobarber-api.git
-
Install the project dependencies:
cd gobarber-api yarn
or using npm:
cd gobarber-api npm install
-
Create the
.env
file for the environment variables values of the application. You can use the.env.example
as a template:cp .env.example .env
Edit the file and set the values according to the values previously used during the creation of the containers.
For the mailing service you can use Mailtrap to create a email for development and testing purposes.
For the Sentry DSN token its necessary to create an account in Sentry and follow the instructions to generate it.
-
Run sequelize migrations to create the database tables:
yarn sequelize db:migrate
-
Open a terminal window and start the queue service (Reponsible to deliver emails):
yarn queue
-
Open another terminal window and start the development server:
yarn dev
The GoBarber API runs at:
http://localhost:3333
-
You are done with configuration! I hope everything is alright and you are ready to code! 🎉
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.
David Oliveira - oliveiradavid.dev@gmail.com
Project Link: https://github.com/dzvid/gobarber-api