diff --git a/.env b/.env new file mode 100755 index 0000000..9a79325 --- /dev/null +++ b/.env @@ -0,0 +1,17 @@ +## PORT +PORT=3000 + +## MongoDB URI +DB_URI= mongodb://mongo:27017/ecommerce + +## JWT access token +JWT_SECRET_KEY=chaveSecreta +JWT_EXPIRE_TIME=1h + +## GMAIL +MAILER_APP_EMAIL=SENDEREMAIL +MAILER_APP_PASSWORD=SENDERPASSWORD + +## STRIPE +STRIPE_SECRET=Create: https://dashboard.stripe.com/register +STRIPE_WEBHOOK_SECRET=Create: https://dashboard.stripe.com/register \ No newline at end of file diff --git a/README.md b/README.md old mode 100644 new mode 100755 index 85f3a08..192945f --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Node.js-Full-E-Commerce-RESTFul-API-with- Cash and Online Payment ![dotenv](https://img.shields.io/badge/dotenv-3982CE?style=for-the-badge&logo=dotenv&logoColor=white1) ![swagger](https://img.shields.io/badge/swagger-00FF00?style=for-the-badge&logo=swagger&logoColor=white) ![eslint](https://img.shields.io/badge/eslint-8A118C?style=for-the-badge&logo=eslint&logoColor=white) - ![prettier](https://img.shields.io/badge/prettier-8A118C?style=for-the-badge&logo=prettier&logoColor=white) + ![prettier](https://img.shields.io/badge/prettier-8A118C?style=for-the-badge&logo=prettier&logoColor=white) ![docker-compose](https://img.shields.io/badge/docker-compose-%232496ED.svg?style=for-the-badge&logo=docker&logoColor=white)
@@ -51,46 +51,104 @@ Node.js-Full-E-Commerce-RESTFul-API-with- Cash and Online Payment ## Installation -1. **Clone the Repository:** - Use the `git clone` command to clone the GitHub repository to your local machine. + + +## Docker Support - "Simplify Your Development with Docker and Docker Compose!" + +E-shtery-app comes with Docker Compose configuration, so you can run the project easily in a containerized environment. No need to worry about setting up dependencies, as Docker Compose takes care of that for you. + +### Prerequisites + +Before you begin, make sure you have **Docker** and **Docker Compose** installed on your machine. + +1. **Install Docker on Linux (Ubuntu):** + + Run the following commands in your terminal: + ```bash - git clone https://github.com/alin00r/Node.js-Full-E-Commerce-RESTFul-App-with-Payment + sudo apt-get update + sudo apt-get install -y docker.io ``` -2. **Initialize a Package.json File (if not already done):** - If your project doesn't already have a `package.json` file, you can create one by running: + +2. **Install Docker Compose:** + + Run the following commands to install Docker Compose: + ```bash - npm init - # or - yarn init + sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose + sudo chmod +x /usr/local/bin/docker-compose ``` -3. **Install depends** + +### Running the Project with Docker Compose + +1. **Clone the Repository:** + Clone the GitHub repository to your local machine: + ```bash - npm install + git clone https://github.com/alin00r/Node.js-Full-E-Commerce-RESTFul-Api-with-Payment.git ``` -4. **Setting up env variables**
- - **Please first specifiy your database engine** +2. **Navigate to the Project Directory:** + Change to the project directory: - ```properties - ## PORT - PORT=YOUR PORT HERE + ```bash + cd Node.js-Full-E-Commerce-RESTFul-App-with-Payment + ``` - ## MongoDB URI - DB_URI= YOUR DATABASE URI +3. **Run the Docker Compose Command:** + + The project already includes the `docker-compose.yml` file. To start the application and all its services (including the MongoDB container), simply run: - ## JWT access token - JWT_SECRET_KEY=YOUR JWT ACCESS TOKEN SECRET - JWT_EXPIRE_TIME=YOUR JWT EXPIRE TIME + ## Docker Compose Workflow - ## GMAIL - MAILER_APP_EMAIL=SENDER EMAIL - MAILER_APP_PASSWORD=SENDER PASSWORD +To start the services in detached mode, where the containers are running in the background, use the following command: + +```bash +docker-compose up -d +``` +This will build the images and start the containers. + +## Bash with Logs +If you want to view the logs of the running services, you can execute the following command: + +```bash +docker-compose up +``` +This command will start the services and continuously display the logs in the terminal. To run commands inside the containers while monitoring logs, open another bash session for your commands. + +## Accessing Containers via Docker Exec + +To execute commands inside the Node container, use the following command: + +```bash +docker exec -it node sh +``` +This will open a bash shell inside the node container. + +For accessing the MongoDB container, use: + +```bash +docker exec -it mongo sh +``` +This command will open a bash shell inside the mongo container, allowing you to interact with the database directly. + + + +4. **Access the Project:** + + After running the command above, the project will be available at `http://localhost:3000`. You can also check your MongoDB container on `localhost:27017` if needed. + +5. **Stop the Docker Containers:** + + To stop the running containers, use: + +```bash +docker-compose down +``` +This setup will allow you to run the project seamlessly using Docker and Docker Compose, simplifying your development workflow. Happy coding! +![docker-compose](https://img.shields.io/badge/docker-compose-%232496ED.svg?style=for-the-badge&logo=docker&logoColor=white) - ## STRIPE - STRIPE_SECRET=Your STRIPE SECRET KEY - STRIPE_WEBHOOK_SECRET=Your STRIPE WEBHOOK SECRET KEY - ``` ## Routes diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100755 index 0000000..256d9fa --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,44 @@ +version: '3' + +services: + nodeService: + image: node:20-alpine + container_name: node + user: "node" + working_dir: /home/node/app + environment: + - NODE_ENV=development + - DB_URI=mongodb://mongo:27017/ecomerce + volumes: + - ./:/home/node/app + ports: + - 3000:3000 + command: > + sh -c " + npm install && + npm run start:dev + " + depends_on: + - db + networks: + - ecomerce + + db: + image: mongo:3 + container_name: mongo + environment: + - MONGO_INITDB_DATABASE=ecomerce + - MONGO_INITDB_ROOT_USERNAME=root + - MONGO_INITDB_ROOT_PASSWORD=root + + volumes: + - ./data:/data/db + - ./mongo-init:/docker-entrypoint-initdb.d + ports: + - "27017:27017" + networks: + - ecomerce + +networks: + ecomerce: + driver: bridge diff --git a/server.js b/server.js old mode 100644 new mode 100755