npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@angstone/cement-basic

v2.0.2

Published

Environment constants, a logger and an error handler acting as TypeScript boilerplate

Downloads

14

Readme

The Cement Basic Module

Angstone Cement Basic Module

Environment constants, a logger and an error handler acting as TypeScript boilerplate

contains:

  • env
  • logger (with chalk)
  • error (good dealer)
  • signature

install

npm install @angstone/cement-basic

use

import {
  signature,
  logger,
  error,
  ENVS,
  LOGLEVELS
} from '@angstone/cement-basic'

// Set environment variables

process.env.APP_ENV = ENVS.DEV // or ENVS.PROD
process.env.APP_LOGLEVEL = LOGLEVELS.DEV_NOTE // or other

// call your app signature
signature()

// be happy and enjoy! :)

logger.note('This app is amazing, lets code it!')
logger.dev('That is the result of the date.now(): ', Date.now())
logger.fatal('This is very bad! :(')
logger.error('This is a expected common error :/')

let myError: Error
myError = error.is(
  'this specific one error',
  'and contains',
  { several: 'details' }
)
// it uses new Error(..) internally

error.op('operational expected error') // prints if LOGLEVELS allows
error.op(new Error())
error.op(myError)

/*
* terminates the application if APP_ENV is set to
* ENVS.PROD ('prod')
*/
error.fatal('really bad error')
error.fatal(new Error())
error.fatal(myError)

error.throw('Error that I wont deal with now, but upstairs in code')
error.throw(new Error('any type that extends Error'))
error.throw(myError)

// Practical sample:

logger.note('Doing Stuff')
await someNiceAndCleanAsyncTask.catch(error.throw)
await otherGoodTask.catch(error.op) // that doesn't matter a lot
logger.dev('Hey devs, pay attention on this task:')
await importantTask.catch(error.fatal) // a failure here restart app

env

The env define default environment variables.

Always use process.env.APP_{YOUR ENV VARIABLE}

Exports process.env as env

logger

The logger wraps your way of handling your logs. Exposes 4 functions from interface ILogger. Comes with a default implementation called defaultLogger witch just prints in the console.

  • fatal(...any): for red fatal errors
  • error(...any): for yellow operational errors
  • note(...any): for blue execution notes
  • dev(...any): for bright purple dev notes

Each ones prints the console only if the APP_LOGLEVEL environment variable allows your kind. They are:

LOGLELEVELS.FATAL LOGLELEVELS.ERROR LOGLELEVELS.NOTE LOGLELEVELS.DEV_NOTE

exports the default implementation and the function useLogger to setup yours

error

The error wraps your way of handling your errors. Exposes 4 functions from interface IError.

Comes with a default implementation called defaultError witch just log errors and also (gracefully?) stops application in case of fatal error.

  • is(message, details): create a default AppError
  • op(message|Error, details): handle operational error
  • fatal(message|Error, details): handle fatal error also (gracefully?) stops application if APP_ENV is set to ENVS.PROD
  • throw(message|Error, details): throw an error upstairs in code

They use logger.fatal for fatal and logger.error for operational

exports the default implementation and the function useError to setup yours

signature

You use this by importing and running the signature() function in the beginning of your code, after setup of you environment variables.

It prints a friendly review of your package.json and register the environment variable APP_LOADED_AT in milliseconds.

You NEED this to make sure env, logger, and error modules are going to work as default expected.

Indeed, THIS IS A BOILERPLATE, that is also a real-world-case-in-use-by-me-right-now useful npm module.

Act as TypeScript Node Boilerplate for cement framework

Features:

  • tslint
  • prettier
  • tslint-config-prettier
  • typescript
  • ts-node
  • nodemon
  • mocha
  • chai
  • chai-like
  • chai-things
  • sinon
  • sinon-chai
  • nyc (coverage)
  • source-map-support (for use with coverage)
  • supertest
  • request
  • request-promise-native
  • express
  • cors
  • wallaby
  • cron
  • chalk
  • Docker's Composition