This is a NestJS project structured using hexagonal architecture. It uses MongoDB to store user documents and Axios to make HTTP requests. The project also includes Docker and Docker Compose configurations for easy setup and deployment.
- Getting Started
- Project Structure
- Running the Application
- Using Docker
- Using Docker Compose
- Endpoints
- Contributing
- License
- Clone the repository:
git clone https://github.com/sallesricardo/register-nest-mongodb.git
cd register-nest-mongodb
- Install the dependencies:
npm install
or
yarn
or
pnpm install
- Create a
.env
file in the root directory and add the following environment variables:
PORT=3000
MONGODB_DEFAULT_ROOT=root
MONGODB_DEFAULT_PASSWORD=123456
MONGODB_APP_USER=app
MONGODB_APP_PASSWORD=123456
MONGODB_HOST=mongodb
MONGODB_PORT=27017
MONGODB_DATABASE=customer
LOCATION_API_URL=https://viacep.com.br/ws/{zipcode}/json/
If you want to use mongodb-express to admin the MongoDB from the docker compose, add this lines:
MONGO_EXPRESS_ROOT=admin
MONGO_EXPRESS_PASSWORD=1234
src/
|-- adapters/
| |-- mongodb/
| |-- user.repository.ts
| |-- user.schema.ts
| |-- viacepApi/
| |-- location.repository.ts
| |-- location.schema.ts
|-- core/
| |-- domain/
| |-- location.entity.ts
| |-- user.entity.ts
| |-- use-cases/
| |-- create-user.use-case.ts
| |-- find-all-users.use-case.ts
| |-- find-user.use-case.ts
|-- modules/
| |-- app.module.ts
| |-- user.module.ts
|-- ports/
| |-- location/
| |-- location.repository.ts
| |-- user/
| |-- user.controller.ts
| |-- user-repository.ts
|-- app.controller.ts
|-- app.service.ts
|-- main.ts
- Start the MongoDB server:
docker run -d -p 27017:27017 --name mongodb mongo
- Run the application:
npm run start
or
yarn start
or
pnpm start
The application will be available at http://localhost:3000
.
Build the Docker image for the application:
docker build -t register-nest-mongodb-project .
Run the Docker container:
docker run -d -p 3000:3000 --name register-nest-mongodb-project --link mongodb:mongo register-nest-mongodb-project
The application will be available at http://localhost:3000
.
-
The file
docker-compose.yml
is already configured in the repository with the project, MongoDB, and mongodb-express. -
Start the services:
docker-compose up -d
The application will be available at http://localhost:3000
.
-
POST /users
: Create a new user- Request body:
{ "name": "John", "cpf": "123.456.789-00", "email": "john@domain.com", "phone": "11999991234", "birth": "1970-01-01", // YYYY-MM-DD "zipcode": "01001-000" }
- Request body:
-
GET /users
: Get all users
GET /external-data
: Fetch external data
- Fork the repository
- Create a new branch (
git checkout -b feature/your-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin feature/your-feature
) - Create a new Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.