Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/edwinmambo/storefront-backend
A storefront backend api that connects to the database for communication with the frontend
https://github.com/edwinmambo/storefront-backend
api backend bcrypt database express jasmine jwt nodejs postgresql udacity
Last synced: 5 days ago
JSON representation
A storefront backend api that connects to the database for communication with the frontend
- Host: GitHub
- URL: https://github.com/edwinmambo/storefront-backend
- Owner: edwinmambo
- License: other
- Created: 2023-01-25T02:39:57.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-03-27T17:05:32.000Z (over 1 year ago)
- Last Synced: 2024-10-31T05:41:50.729Z (about 2 months ago)
- Topics: api, backend, bcrypt, database, express, jasmine, jwt, nodejs, postgresql, udacity
- Language: TypeScript
- Homepage:
- Size: 164 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# Storefront Backend Project
## Introduction
This repo contains a storefront backend api that connects to the database for communication with the frontend. The API needs are stated in `REQUIREMENTS.md`
## Required Technologies
This application makes 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## Setup
1. ### Get the project locally
Clone the project here on github
```bash
git clone https://github.com/edwinmambo/storefront-backend.git
```2. ### Satisfy the following prerequisites
- Have docker installed
```bash
#check if docker and docker compose are installed
docker version
docker compose version
```- I use `yarn` as the package manager
- create an `.env` in file with the following variables:```text
POSTGRES_HOST
POSTGRES_DB
POSTGRES_TEST_DB
POSTGRES_USER
POSTGRES_PASSWORD
ENV
BCRYPT_PASSWORD
SALT_ROUNDS
TOKEN_SECRET
```The default values I use are the following:
- host: 127.0.0.1
- db: full_stack_dev
- test db: full_stack_dev_test
- user: full_stack_user
- password: password123
- env: dev**NOTE:** bcrypt password, salt rounds and token secret are of your own choosing.
3. ### Install the dependencies
```bash
npm install --global yarn
yarn
```4. ### Set up db
For both the dev and test environments:
Run the container from `docker-compose.yml`
```bash
# runs on port 5432
docker compose up
```Connect to the container and run the following to setup the database (_Use values in your `.env` file_):
**Create a user**
```bash(psql)
CREATE USER full_stack_user WITH PASSWORD 'Password123';
```**Create Databases**
```bash(psql)
CREATE DATABASE full_stack_dev;
CREATE DATABASE full_stack_dev_test;
```**Grant all privileges on both databases to user**
```bash(psql)
GRANT ALL PRIVILEGES ON DATABASE full_stack_dev TO full_stack_user;
GRANT ALL PRIVILEGES ON DATABASE full_stack_dev_test TO full_stack_user;
```5. ### Run the api
```bash
# In a separate terminal
yarn watch
```6. ### Testing
```bash
yarn test
```## Usage
The server will run on `localhost:3000/` or `0.0.0.0:3000` where the api will be under the specific endpoint as in `REQUIREMENTS.md`
## Examples
Products: `http:localhost:3000/products`
Users: `http:localhost:3000/users`
Orders: `http:localhost:3000/orders`