Giter VIP home page Giter VIP logo

nodejs-tealicious-shop's Introduction

For the better format of reading please visit: https://yentraquan.shop/docs

Everything in this document is work well in Ubuntu 23.04 (my local desktop) and Ubuntu 22.04 (my server run in AWS).

The live demo version: https://yentraquan.shop/

I. Install Make and Docker

    1. Install make (for run Makefile with predefined commands)
    • Linux
        sudo apt install make
    • Mac OS
        brew install make
  • Window

    • Install Chocolatey first (if it's not already installed)
        Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
    
    • Install Make
        choco install make
    1. Install Docker

II. Run with Docker Compose

You have the option to run without Docker below.

Step 1: Setup the User Acceptance Testing Environment

  • While you have the option to use other environments, for convenient testing, it is recommended to use this environment. It requires only a single command to bring everything up.

  • This environment is designed for running user acceptance testing. The hosts for Postgres and MongoDB are specified by the container's name (not the IP address). The configuration file is located at env/uat.env.

APP_PORT=8080

MG_DB_HOST=mongo-db
MG_DB_PORT=27017
MG_DB_NAME=tealicious_db
MG_DB_USER=tealicious_shop
MG_DB_PASSWORD=tealicious_shop

PG_DB_HOST=postgres
PG_DB_PORT="5432"
PG_DB_NAME="tealicious_db"
PG_DB_USER="postgres"
PG_DB_PASSWORD="0000"
PG_DATABASE_URL="postgresql://${PG_DB_USER}:${PG_DB_PASSWORD}@${PG_DB_HOST}:${PG_DB_PORT}/${PG_DB_NAME}?schema=public"


API_URL=https://yentraquan.shop

VNP_TMN_CODE=
VNP_HASH_SECRET=
VNP_URL=https://sandbox.vnpayment.vn/paymentv2/vpcpay.html
VNP_API=https://sandbox.vnpayment.vn/merchant_webapi/api/transaction
VNP_RETURN_URL=http://localhost:8080/api/payment/vnpay_return

Step 2: Run Docker Compose with one command

  • Ensure no Docker containers are running on ports 8080, 80, 5432 and 27017.
  • Ensure no Docker containers named postgres, mongo-db and tealicious-shop are running.
  • With just a single command, everything will be ready to use. Note that during the initial run, it may take some time to download all the dependencies and images.
    make uat_up

I discovered that Windows users (only Windows) can pass environment variables through the command line as Linux and MacOS. Therefore, you can execute the following command in PowerShell in case you use Windows to run the application:

    $env:MODE='uat'; docker compose -f docker-compose-uat.yml up -d

After the application is running, you can access it at: http://localhost (run in port 80)

To remove the application and images, run:

    make uat_down

III. Run without Docker (not suggested)

Step 1: Install packages and dependencies

    1. Install package
    npm install
    1. Install dotenv-cli
    npm install -g dotenv-cli

Step 2: Start Database in Docker by using Make

This command will start Postgres and MongoDB in Docker automatically.

    make init_db

If you want to remove it just run

    make rm_db

Step 3: Step local environment variables

Local Environment Configuration:

The local.env file, located in the env folder, has already been created. This file contains all the necessary environment variables required to run the application.

APP_PORT=8080

MG_DB_HOST=localhost
MG_DB_PORT=27017
MG_DB_NAME=tealicious_db
MG_DB_USER=tealicious_shop
MG_DB_PASSWORD=tealicious_shop

PG_DB_HOST=localhost
PG_DB_PORT="5432"
PG_DB_NAME="tealicious_db"
PG_DB_USER="postgres"
PG_DB_PASSWORD="0000"
PG_DATABASE_URL="postgresql://${PG_DB_USER}:${PG_DB_PASSWORD}@${PG_DB_HOST}:${PG_DB_PORT}/${PG_DB_NAME}?schema=public"

API_URL=https://yentraquan.shop

VNP_TMN_CODE=
VNP_HASH_SECRET=
VNP_URL=https://sandbox.vnpayment.vn/paymentv2/vpcpay.html
VNP_API=https://sandbox.vnpayment.vn/merchant_webapi/api/transaction
VNP_RETURN_URL=http://localhost:8080/api/payment/vnpay_return

I also have a file named prod.env containing the same structure, but it is connected to my server informaton, so I have already removed it already.

Step 4: Migrating and Seeding Database

When the database is ready, run the following command to migrate the database:

    1. Migrate the database
        make db_migrate env=local

    You can run it with env=prod or env=uat if you want to migrate the production or user acceptance testing database.

    1. Seed the database
        make db_seed env=local

Step 5: Build and Run the Application

    1. Build the application
        npm run build
    1. Run the application:
    • 2.1. Run in production mode
        make start env=local
    • 2.2. Run in debug mode (you dont need to build at step 5.1)
          make run env=local

You can run it with env=prod or env=uat if you want to run the production or user acceptance testing application.

After the application is running, you can access it at: http://localhost:8080 (run in port 8080)

nodejs-tealicious-shop's People

Contributors

anthanhphan avatar edwardpham94 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.