1.1.0 • Published 1 day ago

@beecode/msh-app-boot v1.1.0

Weekly downloads
-
License
mit
Repository
github
Last release
1 day ago

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
1.1.0

1 day ago

1.0.4

5 days ago

1.0.3

6 days ago

1.0.2

24 days ago

1.0.1

29 days ago

1.0.0

1 month ago

0.1.1

12 months ago

0.1.0-alpha

1 year ago