E-Commerce api project for udacity fullstack web nanodegree
src
├─ config
│ └─ db.ts
├─ handlers
│ ├─ dashboard.ts
│ ├─ home.ts
│ ├─ orderProducts.ts
│ ├─ orders.ts
│ ├─ products.ts
│ └─ users.ts
├─ middlewares
│ └─ Error.ts
├─ models
│ ├─ Order.ts
│ ├─ Order_Products.ts
│ ├─ Product.ts
│ └─ User.ts
├─ services
│ └─ Dashboard.ts
├─ tests
│ ├─ helpers
│ │ └─ reporter.ts
│ ├─ models
│ │ ├─ orderSpec.ts
│ │ ├─ productSpec.ts
│ │ └─ userSpec.ts
│ └─ routes
│ ├─ orderSpec.ts
│ ├─ productSpec.ts
│ └─ userSpec.ts
├─ uploads
│ ├─ categories
│ ├─ products
│ └─ profiles
├─ utils
│ ├─ jwt.ts
│ └─ multer.ts
└─ server.ts
Head over to REQUIREMENTS
Install the project dependencies
npm install
- creating user
CREATE USER shop_user WITH PASSWORD 'password123';
- create both development and testing db
CREATE DATABASE shop;
CREATE DATABASE shop_test;
- grant all privileges on both databases
\c shop;
GRANT ALL PRIVILEGES ON DATABASE shop To shop_user;
\c shop_test
GRANT ALL PRIVILEGES ON DATABASE shop_test To shop_user;
- setting enviroment variables
touch .env
nano .env
## place the enviroment variables below inside the .env file
# .env
APP_PORT=3000
POSTGRES_HOST=localhost
POSTGRES_USER=shop_user
POSTGRES_DB=shop
POSTGRES_PASSWORD=password123
POSTGRES_TEST_DB=shop_test
ENV=test
BCRYPT_PASS=thisissupersecretpassword
SALT_ROUNDS=10
PEPPER=password
JWT_SECRET_KEY=thisissupersecretpassword
- port of the posgres database server
5432
- port of the backend: the server runs localhost
- package installation instructions
Running
- testing db
db-migrate up -e test
- development db
db-migrate up -e dev
or simply run
npm run migrate
Rollingback
db-migrate down
- to run on compiled files
npm run dev
- to run on typescript files
npm run start:dev
To run tests, you need only two steps
- Export ENV to test
export ENV=test
- Run testing command, which will build the project and run the tests, this step is so important because
jasmine
tests the compiled js code
npm run build-test
or simple run
npm run test