项目作者: TRIPTYK

项目描述 :
This repository contains 3rd party REST API boilerplate Express.js, Typescript, TypeORM based.
高级语言: TypeScript
项目地址: git://github.com/TRIPTYK/nfw.git
创建时间: 2019-01-18T14:07:57Z
项目社区:https://github.com/TRIPTYK/nfw

开源协议:MIT License

下载


alt text

NFW a node Typescript boilerplate

Test
Lint
CodeQL

This repository contains a JSON-API REST API boilerplate using NFW-CORE.

:warning: : ESM only, no CommonJS modules.

Requirements

  • Typescript >= 4.9.x (waiting on tsyringe to move to 5.x)
  • node >= 18.x
  • pnpm 8.x

Install

Any package manager should do the trick but i recommend using Pnpm.

  1. pnpm i

Install the database container.

  1. docker compose up -d

Environments

You must create a config/env/<NODE_ENV>.env file for each env at the root of your project.

The structure of the env file is validated and can be found in the src/api/services/configuration.service.ts service.

Scripts

Start from dev env

  1. pnpm start:dev

Start from test env

Useful for debugging

  1. pnpm start:test

MIKRO-ORM CLI

  1. pnpm mikro-orm:cli <any command>

Production and deployments

You need to transpile (or bundle) the Typescript. And then run node against it. it’s up to you.

  1. pnpm tsc
  2. # rollup ...
  3. # docker containers ...

Tests

Runs the tests with vitest.
The migrations are run and database is cleared before testing.

  1. pnpm test

With beautiful UI in watch mode and coverage

  1. pnpm test -- --ui --watch --coverage

In watch mode

  1. pnpm test -- --watch

File structure

  • config: config files (some config files that cannot be moved stay in root)
  • database: the docker database init files.
  • dist: the typescript output folder
  • src
    • api: transport and configuration related files.
    • database: database and ORM related files.
  • tests:
    • mocks: mocks folder
    • src: the test files folder
      • acceptance: acceptance tests files
      • integration: integration tests files
      • unit: unit tests files
    • static: static files (png,pdf, …) for testing
    • utils: utils for testing

Notes

  • App must not depend on tests folder.
  • Path aliases are used in typescript to have clearer imports and separation. You cannot import app into app. Import must be relative when the import in the same path.