Skip to content

Latest commit

 

History

History
131 lines (92 loc) · 2.55 KB

framework.md

File metadata and controls

131 lines (92 loc) · 2.55 KB

Framework Usage

Uses AppModule.boot() to fully instantiate an application server.


Installation

1. Create and initialize a new Node.js project, then install Typescript dependencies as well as this package.

We recommend using pnpm as you package manager, and ts-node-dev as your live reload tool:

mkdir my-project
cd my-project

git init
npm init -y

npm i -g pnpm
pnpm i -DE typescript @types/node ts-node-dev
pnpm i -E @bechara/crux

tsc --init

2. Create a main.ts file at /source with the following content:

// /source/main.ts
import { AppModule } from '@bechara/crux';

void AppModule.boot();

3. Add the following dev script at your package.json:

{
  "dev": "tsnd --exit-child --rs --watch *.env --inspect=0.0.0.0:9229 ./test/main.ts"
}

4. Boot the application using:

pnpm dev

You may validate its functionality by sending an HTTP request to GET /.

The response shall be an object containing your machine information:

{
  "system": {
    "version": "Windows 10 Pro",
    "type": "Windows_NT",
    "release": "10.0.19041",
    "architecture": "x64",
    "endianness": "LE",
    "uptime": 614041
  }
  // ...
}

Development

Usage of this framework follows NestJS Documentation with some additions.

Recommended core concepts before proceeding are:

When developing, you should be aware of the following differences:

1. All imports should come from @bechara/crux instead of @nestjs/common and @nestjs/core.

Instead of:

import { Injectable } from '@nestjs/common';

Use:

import { Injectable } from '@bechara/crux';

2. All *.module.ts files at your source directory will be automatically loaded by the wrapper at main.ts, there is no need to add them to a global module.

Instead of:

import { Module } from '@nestjs/common';
import { FooModule } from './foo/foo.module';
import { BarModule } from './bar/bar.module';
import { BazModule } from './baz/baz.module';

@Global()
@Module({
  imports: [
    FooModule,
    BarModule,
    BazModule,
  ],
})
export class AppModule { }

Use:

import { AppModule } from '@bechara/crux';

// Foo, Bar and Baz module will be automatically
// loaded as long as they are inside source and
// named *.module.ts
void AppModule.boot();

Back to title