Skip to content

TRIPTYK/nfw

Repository files navigation

alt text

NFW a node Typescript boilerplate

Test Lint CodeQL

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

⚠️ : 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.

pnpm i

Install the database container.

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

pnpm start:dev

Start from test env

Useful for debugging

pnpm start:test
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.

pnpm tsc
# rollup ...
# docker containers ...

Tests

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

pnpm test

With beautiful UI in watch mode and coverage

pnpm test -- --ui --watch --coverage

In watch mode

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.