@beecode/msh-app-boot
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

Build Status codecov GitHub license
NPM

msh-app-boot

Micro-service helper: app initializer

This project is intended to be used in typescript project to help with app initialization.

Install

npm i @beecode/msh-app-boot

Diagram

vision-diagram

Usage

basic-example

After FistInitiable is finished SecondInitiable and ThirdInitiable are run in parallel

// ./initiate/first-initiable.ts
import { LifeCycle } from '@beecode/msh-app-boot'

export class FirstInitiable extends LifeCycle {
  constructor() {
    super({ name: 'First initiable' })
  }

  protected async _createFn(): Promise<any> {
    console.log('%%%%%% First create') // eslint-disable-line no-console
  }

  protected async _destroyFn(): Promise<any> {
    console.log('%%%%%% First destroy') // eslint-disable-line no-console
  }
}



// app.ts
import { AppFlow } from '@beecode/msh-app-boot'

export class App extends AppFlow {
  public constructor() {
    super(new FirstInitiable(), [new SecondInitiable(), new ThirdInitiable()])
  }
}


// index.ts
import { LogLevelType } from '@beecode/msh-node-log'
import { ConsoleLogger } from '@beecode/msh-node-log/console-logger.js'

import { NodeAppLogger } from '@beecode/msh-logger/dist/util/logger'

import { AppStarter } from '@beecode/msh-app-boot'
import { App } from './app'

NodeAppLogger(new ConsoleLogger({ logLevel: LogLevelType.DEBUG }))

new AppStarter(new App())
  .start()
  .catch((err) => console.log(err)) // eslint-disable-line no-console

after running example (./test/basic-example/index.ts)

$ npx ts-node ./index.ts 
2021-11-20T01:07:53.198Z - DEBUG:  First initiable Create START
%%%%%% First create
2021-11-20T01:07:53.200Z - DEBUG:  First initiable Create END
2021-11-20T01:07:53.200Z - DEBUG:  Second initiable Create START
%%%%%% Second create
2021-11-20T01:07:53.201Z - DEBUG:  Third initiable Create START
%%%%%% Third create
2021-11-20T01:07:53.201Z - DEBUG:  Second initiable Create END
2021-11-20T01:07:53.201Z - DEBUG:  Third initiable Create END

Readme

Keywords

none

Package Sidebar

Install

npm i @beecode/msh-app-boot

Weekly Downloads

38

Version

1.0.2

License

mit

Unpacked Size

87.6 kB

Total Files

40

Last publish

Collaborators

  • milosbugarinovic