Skip to content

ninetydays/nf-backend-ts-template

 
 

Repository files navigation

Backend-typescript-template

This template includes

Graphql endpoints

Express

Database

Typeorm

Linting and formatting

Testing

Installation

  1. Make sure you have node, yarn, docker installed.
  2. install dependencies
$ yarn install
  1. running docker container
$ docker-compose up -d
  1. running DB migration to check database is available
$ yarn typeorm migration:run #local
  1. running test to check everything is fine
$ yarn test

Running locally

$ yarn start

Running scripts

Since scripts are written in TypeScript you need to use ts-node:

$ yarn ts-node path/to/the/script

DB Migration

  1. create new migration
yarn typeorm migration:create -n YourMigrationName

or you can just modify entity and generate migration from the modification

yarn typeorm migration:generate -n YourMigrationName
  1. run migration
yarn typeorm migration:run
  1. rollback migration
yarn typeorm migration:revert

for more information on typeorm cli command.

just run

yarn typeorm

Project Structure

  • dist/: wepback bundle file
  • docker/: docker related file. Currently, it has db init script.
  • src/: source codes
    • src/entities: Entity definations
    • src/lib: Shared library files
    • src/migrations: DB migration files
    • src/resolvers: graphql type defs and resolvers
    • src/routes: express routes
    • src/Api.ts: API server
  • __test__/: test scripts
  • scripts/: miscellaneous scripts
  • READ.md: this file
  • docker-compose.yml: docker config for development and test database
  • ecosystem.config.js: pm2 deployment config
  • ormconfig.js: database connection config
  • package.json: node dependencies and command scripts
  • tsconfig.json: typescript compile options
  • eslint.json: eslint config
  • webpack.config.js: webpack config
  • .env.local: environment variables to load for local NODE_ENV
  • .env.test: environment variables to load for test NODE_ENV
  • babel.config.js: load babel presets for code transpilation
  • jest.config.js: test configuration (paths of files to test)
  • nodemon.json: nodemon setting(run nodemon using ts-node and watch the changes)

About

Backend template using typescript and typeorm

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 83.9%
  • JavaScript 16.1%