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 🙏

© 2025 – Pkg Stats / Ryan Hefner

log-errors

v4.1.0

Published

environment aware error logger that can easily be plugged into express.js

Readme

Log Errors

Quickstart

var	logErrors 	= require('log-errors'),
	logProd 	= logErrors.production,
	logDev 		= logErrors.development;

try {
	throw new error("funky");
} catch (e) {
	logDev(e);
}

This will output in colored text:

Error name: Error

Error object:

{  	Error: 		funky,
   	message: 	'funky',
   	type: 		undefined,
   	stack:  	Getter/Setter,
   	arguments: 	undefined }

Stack trace:

'Error: funky
    at Object.<anonymous> (/home/andy/lib/modules/npm/log-errors/lib/development.js:16:12)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.runMain (module.js:492:10)
    at process.startup.processNextTick.process._tickCallback (node.js:244:9)'

Using in Express.js

It will also log request url + query info.

var	logErrors 	= require('log-errors'),
	logProd 	= logErrors.production,
	logDev 		= logErrors.development;


// add this at very bottom (below all route handlers)
// it is designed to catch the errors passed by next(err) calls

app.configure('production', function() {
	app.use(logProd);
});

app.configure('development', function() {
	app.use(logDev);
	// equates to:
	// app.use(function(err, req, res, next) {
		// logDev(err, req, res, next);
	// });
});

Example Output:

Error name: Error

Request:

url: someurl
query: ?some=random&query=params

Error object:

{  	Error: 		funky,
   	message: 	'funky',
   	type: 		undefined,
   	stack:  	Getter/Setter,
   	arguments: 	undefined }

Stack trace:

'Error: funky
    at Object.<anonymous> (/home/andy/lib/modules/npm/log-errors/lib/development.js:16:12)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.runMain (module.js:492:10)
    at process.startup.processNextTick.process._tickCallback (node.js:244:9)'

Docs

Info printed to STDOUT

  1. error name: (err.name)
  2. error message (err.message)
  3. error logLevel (err.logLevel)
  4. request url (req.url)
  5. request query (req.query)

Log Levels

  • Must be one of the 8 unix log levels used in the Visionmedia Logging Module.
  • Defaults to 'info' level if not passed one of the 8 listed.

Development Logger

Always prints full error in colored text.

var logDev 	= require('log-errors').development;
logDev(new Error('development error msg'));

Production Logger

Will only print error info if error.LogLevel is 3 or below, ie ['error', 'critical', 'alert', 'emergency'].

var logProd	= require('log-errors').production,
	err 	= newError('some message about the error');

err.logLevel = 'critical'
logProd(err);

Using in Conjunction with Custom Errors npm Module

  • If your errors inherit from the custom errors class then the extra error attrs (logLevel, name, message etc) are already added.
  • However, the logger should work fine with the built in base error class too.
var valErr 		= require('custom-errors').general.ValidationError,
	logErrors 	= require('log-errors'),
	logProd 	= logErrors.production,
	logDev 		= logErrors.development;

try {
	throw new valErr("funky");
} catch (e) {
	logDev(e);
}

Outputs:

Error name: Validation

Error object:

{ logLevel: 'warn',
  message: 'funky',
  name: 'Validation',
  resCode: 400,
  [stack]: [Getter/Setter] }

Stack trace:

'Validation: funky
    at Object.<anonymous> (/home/andy/lib/modules/npm/log-errors/lib/development.js:18:12)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.runMain (module.js:492:10)
    at process.startup.processNextTick.process._tickCallback (node.js:244:9)'