This project implements the backend for a storefront application using Node.js, Express, and PostgreSQL. It provides APIs for managing products, users, and orders.
- Node.js (v.20.12.1)
- npm or yarn (v.10.5.0)
- PostgreSQL
- Docker (optional)
- Clone the repository:
git clone https://github.com/yourusername/storefront-backend.git
cd ecommerce-store_backend
-
Install dependencies:
npm install
-
Update .env variables in ./environment by replacing the values if necessary and removing ".template" from the end of each file.
-
Add .env file to root:
NODE_ENV=development
JWT_SECRET=your_jwt_secret
Before running the application, you need to set up the databases for both development and testing environments. This project uses PostgreSQL as the database system.
If you prefer to use Docker to run PostgreSQL (docker setup is already provided):
-
Ensure Docker is installed and running on your system. You can download it from the official Docker website.
-
Navigate to the root directory of the project where the
docker-compose.yml
file is located. -
Permissions: This setup includes an initialization script for PostgreSQL. Run the following from the root folder to ensure the script is executable:
chmod +x ./postgres-init/init-user-db.sh
- Run the following command to start the PostgreSQL containers in detached mode:
docker-compose up --build -d
This grants the necessary permissions to execute the database initialization script when the PostgreSQL container starts.
After setting up your database environment and ensuring all configurations are in place, proceed to run database migrations to set up the required tables and schemas:
-
Build distrubtion folder with
npm run build
(the migrations rely on a dbConfig.js file) -
Setup dev db with
npm run migrate:up
-
Setup test db with
NODE_ENV=test npm run migrate:up
These commands execute the migrations defined in the project, setting up your database schema according to the defined migrations.
Ensure the following steps above have been completed prior to testing:
- Setup the test db according to the steps above
- Add .env to root with
NODE_ENV=test
andJWT_SECRET=token
npm run test
Run tests with npm run test
For development:
npm run start
To watch for changes:
npm run watch
View available routes and data shape here