- Introduction
- Technology Stack
- Project Setup and Running
- Testing
- Important Notes
- Anatomy of storefront endpoints
- Database Schema
- Data Shapes
This is a simple backend API for an online store to handle products, users, orders. It has different endpoints covering all CRUD operations.
This API built with
Node.js
: Back-end JavaScript runtime environment.Express
: Node.js web application framework.Typescript
: Is JavaScript with syntax for types.NPM
: As a package manager.PostgreSQL
: As a Database.db-migrate
: For migrations.jsonwebtoken(JWT)
: For users authorization.Jasmine
: For Unit testing.ESLint
: JS linting tool.prettier
: Code formatting tool.
By following the instruction below , you will be able to set up and run the project locally on your machine.
npm install
You have to create two databases one for development and another for testing.
- open your shell and connect to the default postgres database via psql
psql -U postgres
- create the dev and test database
CREATE DATABASE storefront; CREATE DATABASE storefront_test;
- create a new user
CREATE USER storefront_user WITH PASSWORD 'pass123';
- grant all privileges on the storefront and storefront_test databases to the new user
\c storefront GRANT ALL PRIVILEGES ON DATABASE storefront TO storefront_user; \c storefront_test GRANT ALL PRIVILEGES ON DATABASE storefront_test TO storefront_user;
You need to create .env
file in the root directory and add these environment variables to it.
PORT=3000
POSTGRES_HOST=127.0.0.1
POSTGRES_DB=storefront
POSTGRES_TEST_DB=storefront_test
POSTGRES_USER=storefront_user
POSTGRES_PASSWORD=pass123
ENV=dev
BCRYPT_PASSWORD=spreak-friend-and-enter
SALT_ROUNDS=10
TOKEN_SECRET=NEWStoreFrontTKN!
TEST_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwicm9sZSI6ImFkbWluIiwiaWF0IjoxNjQ1NDk2OTc0fQ.mE1P84E0XJZytIkjs8e41yNFMbja0hdOPVgmKpxuOYs
Use this command to run the migrations, to create the tables in the database.
db-migrate up
Use this command to run the app in watch mode.
npm run watch
- The app will run on port
3000
|localhost:3000
- The database will run on port
5432
Use this command to run the unit tests with jasmin.
npm run test