DEV Community

Cover image for Announcing Ditsmod 2.0 beta (with RealWorld example)
Костя Третяк
Костя Третяк

Posted on • Edited on

Announcing Ditsmod 2.0 beta (with RealWorld example)

Today I'm excited to announce the release of Ditsmod 2.0 beta!

For those who aren’t familiar with Ditsmod, it's NodeJS framework written in TypeScript. To learn more, you can visit our website.

To get started using Ditsmod 2.0 beta, you can get it from github ditsmod/seed:

git clone https://github.com/ditsmod/seed.git ditsmod-app
cd ditsmod-app
yarn
Enter fullscreen mode Exit fullscreen mode

Also, you can browse Ditsmod application containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the RealWorld spec and API.

For most users, Ditsmod is a hitherto unknown framework, so I will present it here as for the first time.

Some major highlights of Ditsmod are:

  • Modular architecture on decorators, which allows you to declaratively describe the structure of the application.
  • Convenient mechanism for specifying and resolving between different application classes: you in constructor specify instances of which classes you need, and DI undertakes a difficult task "how to get it".
  • Ability to write your own extensions (sometimes called plugins) that can be asynchronously initialized and that can depend on each other.
  • Ability to dynamically add and remove modules after starting the web server, without the need to restart.
  • Has OpenAPI support, and has the ability to validate requests based on OpenAPI metadata.
  • To date, Ditsmod is one of the fastest among Node.js web frameworks.

Example controller:

import { Controller, Res, Route } from '@ditsmod/core';

@controller()
export class HelloWorldController {
  constructor(private res: Res) {}

  @route('GET')
  tellHello() {
    this.res.send('Hello World!');
  }
}
Enter fullscreen mode Exit fullscreen mode

Example module that has controllers:

import { featureModule } from '@ditsmod/core';

import { Params } from '@models/params';
import { ArticlesController } from './articles.controller';
import { CommentsModule } from './comments/comments.module';
import { DbService } from './db.service';
import { FavoriteModule } from './favorite/favorite.module';

@featureModule({
  imports: [
    { prefix: 'comments', module: CommentsModule },
    { prefix: 'favorite', module: FavoriteModule },
  ],
  controllers: [ArticlesController],
  providersPerReq: [DbService]
})
export class ArticlesModule {}
Enter fullscreen mode Exit fullscreen mode

Example module that has services only:

import { featureModule } from '@ditsmod/core';
import { JwtModule } from '@ditsmod/jwt';

import { AuthService } from './auth.service';
import { BearerGuard } from './bearer.guard';
import { ModuleConfigService } from './config.service';
import { CryptoService } from './crypto.service';
import { PermissionsGuard } from './permissions.guard';

const jwtModuleWithParams = JwtModule.withParams({ secret: process.env.JWT_SECRET, signOptions: { expiresIn: '1y' } });

@featureModule({
  imports: [jwtModuleWithParams],
  providersPerMod: [ModuleConfigService],
  providersPerReq: [BearerGuard, CryptoService, AuthService, PermissionsGuard],
  exports: [BearerGuard, CryptoService, AuthService, PermissionsGuard]
})
export class AuthModule {}
Enter fullscreen mode Exit fullscreen mode

Ditsmod vs NestJS

Ditsmod is similar to NestJS only because both of these frameworks are inspired by the concepts that Angular has. But Ditsmod under the hood does not have Express, Fastify or other frameworks. Ditsmod is 11% faster than NestJS + Fastify, provided that an instance of controller is created for each request. And more than twice as fast as NestJS + Express. Ditsmod also consumes significantly less memory compared to NestJS.

Thanks to the system of extensions, Ditsmod applications are more expressive and with less code. For example, if you compare OpenAPI modules written in Ditsmod and NestJS, the Ditsmod module is 3.5 times smaller in the number of lines of code or the number of files.

Top comments (0)