omar214 / E-store

API for online store using typescript, express and postgres

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

E-Store API

🚩About

API for online store using typescript, express and postgres

it's the second project for udacity advanced full-stack nano-degree

💻Technologies Used

  • Express Js
  • Postgres
  • Typescript
  • db-migrate for database migrations
  • JWT
  • bcryptJS for hashing passwords
  • Jasmine for testing
  • Express Js

🏁Getting Started

  1. Clone the repository
git clone https://github.com/omar214/E-store.git
  1. Go to the directory of the repository
cd E-store
  1. install dependencies
npm install

4.add .env file

add .env file similar to this

PORT = 5000

ENV = 'dev'
# ENV = 'test'

# database variables
PG_HOST='localhost'
PG_PORT=5432
PG_USER = APP
PG_DATABASE_DEV= 'store_dev'
PG_DATABASE_TEST= 'store_test'
PG_PASSWORD= 123456

# hash pass
SALT = 10
PEPPER = password

# token pass

JWT_PASSWORD = password
  1. create the database

create 2 DBs one for APP and other for test

  CREATE DATABASE store_dev;
  CREATE DATABASE store_test;
  1. create DB User

these users will be used to specify which user at the .env file

  CREATE USER APP WITH PASSWORD '123456';
  CREATE USER test WITH PASSWORD '123456';
  GRANT ALL PRIVILEGES ON DATABASE store_dev TO APP;
  GRANT ALL PRIVILEGES ON DATABASE store_test TO test;
  1. configure database

put the databases data in the database.json similar to this:

{
	"defaultEnv": { "ENV": "NODE_ENV" },
	"dev": {
		"driver": "pg",
		"host": { "ENV": "PG_HOST" },
		"port": { "ENV": "PG_PORT" },
		"database": { "ENV": "PG_DATABASE_DEV" },
		"user": { "ENV": "PG_USER" },
		"password": { "ENV": "PG_PASSWORD" }
	},
	"test": {
		"driver": "pg",
		"host": { "ENV": "PG_HOST" },
		"port": { "ENV": "PG_PORT" },
		"database": { "ENV": "PG_DATABASE_TEST" },
		"user": { "ENV": "PG_USER" },
		"password": { "ENV": "PG_PASSWORD" }
	}
}

🏁Scripts

  • npm i install all the packages
  • npm start to run the APP after build
  • npm run build to compile the ts files
  • npm run dev run app using nodemon
  • npm migrate:run up all DB migrations
  • npm migrate:run reset DB

About

API for online store using typescript, express and postgres

License:MIT License


Languages

Language:TypeScript 89.3%Language:JavaScript 10.7%