Coder Social home page Coder Social logo

boa's Introduction

boa CircleCI

Toolkit for building backends in Node.js.

Configuration

  • Read string environment variable: Config.string('Redis.Password') - This will read the environment variable REDIS_PASSWORD and will error out if the value is empty.
  • Read string environment variable with default value: Config.string('Redis.Password', 'blah') - This will try to read the environment variable REDIS_PASSWORD and will return blah if the value is empty.
  • Read integer environment variable: Config.int('Redis.Port') - This will read the environment variable REDIS_PORT and try to cast it to an integer. If the casting fails or the value is empty, it will fail.

Preloaded variables:

  • Config.NodeEnv -> process.env.NODE_ENV
  • Config.isTestEnv -> true if NODE_ENV is set to test.
  • Config.isDevelopmentEnv -> true if NODE_ENV is set to development.

Logger

The exported logger is a wrapper around a hidden winston logger, which by default logs to the console. The logging levels can be configured using the environment variable LOGGER_LEVEL - the default is to log warn and above. The levels are as follows:

  • error
  • warn
  • info
  • verbose

All loggers use util.format() & therefore whatever formatters are supported by your node version (see docs).

The logger also comes with some extra builtin utilities:

  • errorf: creates an error object where the message is formatted using the formatter.
  • fatalf: builds an error using errorf() then throws it.
  • debug: takes a namespace as the first parameter and only logs the formatted message if that namespace is enabled using process.env.DEBUG.
import { logger } from '@karimsa/boa'

// errorf
const name = await fetchName()
const err = logger.errorf('Hello, %s', name)
// err = new Error('Hello, ' + name)

// fatalf
logger.fatalf('hello') // throw logger.errorf('hello')

// debug
logger.debug('myapi', 'hello, %s', name)

License

Licensed under MIT license.

Copyright (C) 2019-present Karim Alibhai.

boa's People

Contributors

karimsa avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.