Skip to content

Second Project in Advanced Full-Stack Web Development Nanodegree Program with Udacity and egFWD.

License

Notifications You must be signed in to change notification settings

Mohamed-Hafez24/storefront

Repository files navigation

Storefront Backend Project

Table of Contents

Introduction

This is a simple backend API for an online store to handle products, users, orders. It has different endpoints covering all CRUD operations.

Technology Stack

NPM TypeScript NodeJS Express.js Jasmine Postgres JWT ESLint

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.

Project Setup and Running

By following the instruction below , you will be able to set up and run the project locally on your machine.

1. Install project dependencies

npm install 

2. Database Setup

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;
    

3. Environment Setup

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

4. Run the migration

Use this command to run the migrations, to create the tables in the database.

db-migrate up

5. Running the App

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

Testing

Use this command to run the unit tests with jasmin.

npm run test

Releases

No releases published

Packages

No packages published