Skip to content

Hydra-Gang/difabel-project-be

Repository files navigation

About

Backend of the difabel project. This project is using the project template from BNCC@Bandung RnD division.

Quick Start

  1. Make sure you have installed yarn and PostgreSQL.
  2. Clone the repo
    git clone https://github.com/Hydra-Gang/difable-project-be.git
  3. Install the dependencies
    yarn install
  4. Duplicate the .env.example file to .env and fill the database credentials
  5. Generate JWT secrets
    yarn jwt:generate
  6. (Optional) If you want, you can seed data
    yarn seed
  7. Run the dev server
    yarn auto

Project Structure

<your project>\
 |--scripts\             # User scripts for automating
 |--src\                 # Source folder
     |--configs\         # Application configs
     |--controllers\     # Route controllers
     |--decorators\      # Custom decorators
     |--entities\        # Database models/entities (represents table)
     |--middlewares\     # Custom middlewares
     |--routes\          # Server routes, provides automatic routing
     |--typings\         # Custom types/interface for type assertion
     |--utils\           # Utility classes and functions
         |--api.util.ts  # Server response utility
     |--validations\     # Schemas for validating JSON
     |--app.ts           # Express app and it's configuration
     |--ormconfig.ts     # TypeORM config
     |--server.ts        # Program entry point (db connection is also here)
 |--.eslintrc.json       # ESLint config
 |--tsconfig.json        # TypeScript compiler config
 |--...

Commands

Running:

# compiles the project to `dist` directory
yarn compile

# diagnose the TS compiler
yarn compile:debug

# starts the program (must be compiled first)
yarn start

# automatically compiles and starts the program (not used in production)
yarn auto

Data seeding:

# Add a bunch of prepared data in `seeder.ts` file
yarn seed

Cleans the compiled files (in dist directory):

yarn clean

Linting:

# runs ESLint to `src` directory
yarn lint

# fixes ESLint errors (for fixable errors only)
yarn lint:fix

TypeORM:

# shows TypeORM commands
yarn typeorm -h

# example: shows the migration status
yarn typeorm migration:show

JSONWebToken:

# generate JWT secrets (both access and refresh secrets)
yarn jwt:generate

Environment Variables

Found in the .env file

# the JWT secrets
JWT_ACCESS_SECRET=
JWT_REFRESH_SECRET=

# the postgres database credentials
DB_HOST=
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=

Dependencies

  1. express
    • Node.js backend framework.
    • Extra note, body-parser is already built-in to this package (ex: express.json()) so you don't need to install it.
  2. cors
    • Middleware to enable CORS (Cross-origin resource sharing).
    • Allows the frontend devs to access the backend.
  3. helmet
    • Secures the backend HTTP headers.
    • It doesn't protect you from literally everything, but at least there's something.
  4. http-status-codes
    • To avoid magic numbers and use constants enum, ex: using BAD_REQUEST instead of 400.
  5. joi
    • Library for validating JSON, making it easy to make sure all (or certain) properties exists and valid.
  6. luxon
    • Better date and time library than the default Date from JS.
    • Why not momentjs? It has stopped it's development, check here.
  7. pg
    • PostgreSQL database for our backend projects, although we won't be using this directly, but through typeorm.
  8. typeorm
    • ORM (Object-relational mapping) library for Node.js.
    • Helps us to access the database without a need to write SQL queries.
      • It can prevent typos in SQL query.
      • It can make cleaner codes, thus more readable.
      • It's perfect for TypeScript users.
  9. bcrypt
  10. jsonwebtoken
    • Token based user authentication, we need to know whether user is logged in or not.
    • It's more secure when compared to Cookie and Session.

About

Backend server to support the difabel website

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •