0.1.0 • Published 2 years ago

@cybercoder/nest-json-db v0.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Nest JSON DB

A module that implements node-json-db as a NestJS dynamic module.


Example usage:

Import the module:

import { NestJSONDBModule } from '@cybercoder/nest-json-db';
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
  imports: [
    NestJSONDBModule.forRootAsync({
      useFactory: () => ({
        filename: 'myJSONdbFile',
        // humanReadable: true,
        // separator: '/',
        // saveOnPush: true,
        // syncOnSave: true,
      }),
    }),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

Service usage example:

mport { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';
import { JsonDBService } from '@cybercoder/nest-json-db';
@Controller()
export class AppController {
  constructor(
    private readonly appService: AppService,
    private readonly jsonDBService: JsonDBService,
  ) {}

  @Get()
  getHello(): string {
    this.jsonDBService.push(
      '/',
      {
        new: 'cool',
        json: {
          important: 5,
        },
      },
      false,
    );
    return this.appService.getHello();
  }
}

You can find node-json-db examples and documentation here.