Git Product home page Git Product logo

storefront's Introduction

Storefront Backend Project

Getting Started

This repo contains a backend API for an online store. To get started, clone this repo and run yarn in your terminal at the project root.

You can check the database schema and API endpoints in the REQUIREMENT.md

Technologies

The application use of the following libraries:

  • Postgres for the database
  • Node/Express for the application logic
  • dotenv from npm for managing environment variables
  • db-migrate from npm for migrations
  • jsonwebtoken from npm for working with JWTs
  • jasmine from npm for testing
  • bcrypt from npm for hashing passwords
  • body-parser from npm for parsing incomong requests bodies

Steps

Create And Connect To Database

  • After running the docker container for postgres on PORT 5432. docker-compose up -d.

We shall create the dev and test databases.

  • connect to the default postgres database as the server's root user psql -U postgres.
  • In psql run the following to create a user
    • CREATE USER storefront WITH PASSWORD 'storefront';
  • In psql run the following to create the dev and test database
    • CREATE DATABASE storefront_dev;
    • CREATE DATABASE storefront_test;
  • Connect to the databases and grant all privileges
    • Grant for dev database
      • \c storefront_dev
      • GRANT ALL PRIVILEGES ON DATABASE storefront_dev TO storefront;
    • Grant for test database
      • \c storefront_test
      • GRANT ALL PRIVILEGES ON DATABASE storefront_test TO storefront;

Migration

You can run the command below the create migrations. yarn migrate:up

Environment Variables

You can set your environment variables as below.

HOST=localhost
PORT=3000
NODE_ENV=dev

# Database configurations.
PG_HOST=localhost
PG_USER=storefront
PG_PASSWORD=storefront
PG_DB=storefront_dev
PG_TEST_DB=storefront_test

# Hasing
PEPPER=thisisourapppepper
SALT=10

# JWT secret
JWT_SECRET=thisisjwtsecret
TOKEN_TEST=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwidXNlcm5hbWUiOiJ0ZXN0dXNlcjEiLCJwYXNzd29yZCI6IiQyYiQxMCQ3Z0pQMTRtZUlpdWVCdzMwblBCME4ub2hHRnJjL0MvbVJtUWNxLjQ1dkpyQzVlMlluOFBsbSIsImZpcnN0bmFtZSI6InRlc3QiLCJsYXN0bmFtZSI6InVzZXIiLCJpYXQiOjE2NDM5MzgxMTN9.XuVTOi4-wmDYptOxvZJWWzUwlcoO9Ue_lYz4gdiBq3Y

Automations

All tasks are available through yarn scripts.

Linter/prettier

Code styling check and automatic fix is handled by ESLint. You can execute the command below:

yarn lint
yarn prettier

Typescript transpiling

The backend code is delivered through the ./src folder, and the transformed output is placed under ./dist. You can execute the command below:

yarn build

Seeding database

You can seed development database with users, products and orders to be able to use the API in dev.

yarn seed

Executing Jest test

The test suite validates basic functionality of the images handler helper. You can execute the command below:

yarn test

Executing the server

There are two modes of execution:

  1. Single execution (build and serve the dist/server.js)
  2. Execution with watcher mode and restart enabled on PORT 3000.

The commands to achieve the builds described above are, respectively:

yarn start
yarn watch

storefront's People

Contributors

ahmedamin1700 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.