ibcurt-module-common

This is common module for Hapi Nodejs.

Usage no npm install needed!

<script type="module">
  import ibcurtModuleCommon from 'https://cdn.skypack.dev/ibcurt-module-common';
</script>

README

Seed module

This is common module for Hapi Nodejs.

Setup

This seed is loaded with the following tools/libraries:

  • Husky
  • Jest
  • Prettier
  • Eslint
  • Typescript

Running module in local for test usage

https://docs.npmjs.com/cli/link

Modules

Logger

  • create a Nodejs logger with json format:
import { createLogger } from 'ibcurt-module-common'

const logger = createLogger({
  level: 'debug', // the minimal level that you want to show the log
  serviceName: 'ibcurt-module-common' // the name of service that you want to log
  pretty: false // Default: false, set true when you want to provide the basic prettifier for log lines
  mixin: () => {[key: string]: any} // mixin function when you want to add more thing when call logger function
});

Context

  • this is a wrapper of cls-hooked for creating a Nodejs context
// context.ts
import { Context } from 'ibcurt-module-common'
export default new Context('this is context' /* the context name, you can create the context without put name */);

// setup.ts
import context from './context'
...
context.set('key', 'value');

// use.ts
import context from './context'
...
const value = context.get('key');