API for online store using typescript, express and postgres
it's the second project for udacity advanced full-stack nano-degree
- Express Js
- Postgres
- Typescript
- db-migrate for database migrations
- JWT
- bcryptJS for hashing passwords
- Jasmine for testing
- Express Js
- Clone the repository
git clone https://github.com/omar214/E-store.git
- Go to the directory of the repository
cd E-store
- 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
- create the database
create 2 DBs one for APP and other for test
CREATE DATABASE store_dev;
CREATE DATABASE store_test;
- 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;
- 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" }
}
}
npm i
install all the packagesnpm start
to run the APP after buildnpm run build
to compile the ts filesnpm run dev
run app using nodemonnpm migrate:run
up all DB migrationsnpm migrate:run
reset DB