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/
-
- 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
-
- Install Docker
- Download at: https://www.docker.com/
You have the option to run without Docker below.
-
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
- Ensure no Docker containers are running on ports
8080
,80
,5432
and27017
. - Ensure no Docker containers named
postgres
,mongo-db
andtealicious-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
-
- Install package
npm install
-
- Install dotenv-cli
npm install -g dotenv-cli
This command will start Postgres and MongoDB in Docker automatically.
make init_db
If you want to remove it just run
make rm_db
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.
When the database is ready, run the following command to migrate the database:
-
- Migrate the database
make db_migrate env=local
You can run it with
env=prod
orenv=uat
if you want to migrate the production or user acceptance testing database. -
- Seed the database
make db_seed env=local
-
- Build the application
npm run build
-
- 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)