Documentation chapters
You're looking at legacy documentation.
New multi-language documentation available at https://docs.deepkit.io
Framework

Getting Started

Installation

Deepkit Framework is based on the TypeScript runtime type system @deepkit/type. Make sure to install it first: Deepkit Type: Getting Started.

Next install Deepkit Framework:

npm install ts-node @deepkit/framework

Make sure all peer dependencies are installed. By default NPM 7+ installs them automatically.

To compile your application we need the TypeScript compiler and recommend ts-node to run it easily.

An alternative to using ts-node is to compile the source via the TypeScript compiler and run the JavaScript source directly. This has the advantage that the execution speed for short commands increases dramatically. However, this also adds additional workflow overhead by either running the compiler manually or by setting up a watcher. That's why this documentation uses ts-node in all examples. See the chapter Deployment to learn about compilation.

Write the application

Since Deepkit Framework does not use any configuration files or special folder structure, you can structure your project the way you want. The only two files you need to get started are a TypeScript file app.ts and the TypeScript config tsconfig.json.

We aim have the following files in our project folder:

.
├── app.ts
├── node_modules
├── package-lock.json
└── tsconfig.json
{
  "compilerOptions": {
    "outDir": "./dist",
    "experimentalDecorators": true,
    "strict": true,
    "esModuleInterop": true,
    "target": "ES2020",
    "module": "CommonJS",
    "moduleResolution": "node"
  },
  "reflection": true,
  "files": [
    "app.ts"
  ]
}
#!/usr/bin/env ts-node-script
import { App } from '@deepkit/app';
import { Logger } from '@deepkit/logger';
import { cli, Command } from '@deepkit/app';
import { FrameworkModule } from '@deepkit/framework';

@cli.controller('test')
export class TestCommand implements Command {
    constructor(protected logger: Logger) {
    }

    async execute() {
        this.logger.log('Hello World!');
    }
}

new App({
    controllers: [TestCommand],
    imports: [new FrameworkModule]
}).run();

In this code you see that we defined a test command via the TestCommand class and created a new app, which we directly run(). By executing this script we execute this application.

With the shebang at the first line ("#!...") we can make our script executable using the following command.

$ chmod +x app.ts

And then execute it.

$ ./app.ts
VERSION
  Node

USAGE
  $ ts-node-script app.ts [COMMAND]

TOPICS
  debug
  migration  Executes pending migration files. Use migration:pending to see which are pending.
  server     Starts the HTTP server

COMMANDS
  test

To execute now our test command, we run following command.

$ ./app.ts test
Hello World

HTTP server

When you execute ./app.ts server:start the HTTP/RPC server starts and waits for incoming requests. In order to serve requests, please see the chapter HTTP Controller or RPC controller. But before you do that, please read the chapter Fundamentals first.

Made in Germany