restify4-utils
A set of utils I use a lot when using restify 4.x on projects. If I'm the only one who ever uses this, then I'll have succeeded :)
Installation:
npm i restify4-utils --save
Utils
The following utils are provided:
- A Bunyan logger which simply logs things to
process.stdout
, you can also add additional logging streams / serializers etc to this logger if you need them (see Extending the Bunyan logger below). - A Bunyan audit logger which uses the
bunyanLogger
above and prints timing info for server calls. You can use it as it is, or add it to you server instance via addBunyanAuditLogger. - A formatter wrapper to keep error details from going out in server responses.
- A
server.on('uncaughtException')
handler which logs the exception and sends a vanilla 500 response. - A simple healthcheck route.
Basic Example
'use strict'const restify = const restify4Utils = const port = 8080const logger = restify4UtilsbunyanLogger const server = restify restify4Utils serverserverserverserver restify4Utilsrestify4Utilsrestify4Utils server server server
This example is available here.
Once that server is running, try these cURLs:
curl "http://localhost:8080/error/nodejs/next" -verbosecurl "http://localhost:8080/error/nodejs/throw" -verbosecurl "http://localhost:8080/healthcheck" -verbose
Extending the Bunyan logger
const restify4Utils = const logger = restify4UtilsbunyanLogger// this is just an instance of a Bunyan logger, so go crazy :) // hey look, I"m changing the loggerlogger;