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

restify4-utils

v0.0.5

Published

A set of utils I use a lot when using restify 4.x on projects.

Downloads

3

Readme

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 :)

travis npm standard

Installation:

npm i restify4-utils --save

Utils

The following utils are provided:

Basic Example

'use strict'
const restify = require('restify')
const restify4Utils = require('restify4-utils')

const port = 8080
const logger = restify4Utils.bunyanLogger

const server = restify.createServer({
  log: logger
})

restify4Utils.excludeErrorsFromResponse(server)

server.use(restify.acceptParser(server.acceptable))
server.use(restify.gzipResponse())
server.use(restify.authorizationParser())
server.use(restify.requestLogger())

restify4Utils.handleUncaughtExceptions(server)
restify4Utils.addBunyanAuditLogger(server)
restify4Utils.addHealthCheck(server)

server.listen(port, (err) => {
  if (err) {
    logger.error('Unable to start server', err.stack || err)
    process.exit(1)
  }
  logger.info(`Server listening on port: ${port}`)
})

server.get({
  description: 'Simple GET which returns next(err)',
  path: '/error/nodejs/next'
}, (req, res, next) => {
  // simulates async work
  setTimeout(() => {
    // goes through the formatters to res.send
    next(new Error('Test error'))
  }, 500)
})

server.get({
  description: 'Simple GET triggering an uncaughtException',
  path: '/error/nodejs/throw'
}, () => {
  // simulates async work
  setTimeout(() => {
    // handled by server.on('uncaughtException')
    throw new Error('Test error')
  }, 500)
})

This example is available here.

Once that server is running, try these cURLs:

curl "http://localhost:8080/error/nodejs/next" -verbose
curl "http://localhost:8080/error/nodejs/throw" -verbose
curl "http://localhost:8080/healthcheck" -verbose

Extending the Bunyan logger

const restify4Utils = require('restify4-utils')
const logger = restify4Utils.bunyanLogger
// this is just an instance of a Bunyan logger, so go crazy :)

// hey look, I"m changing the logger
logger.addStream({
  type: 'stream',
  stream: process.stderr,
  closeOnExit: false,
  level: 'error'
});