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

looker

v0.1.0

Published

Looks for files, and loads or requires them

Readme

Looker

A utility library to help finding and loading files or modules. Give looker a set of paths to look in, and then call one of looker's methods to find and load the file. Paths can be specified with a priority, so you can specify a cascading set of places to look and only load the first matching result. This library can also be used to require in javascript files into a node app.

Examples

// Create a new looker
var look = new require('looker')();

// Add some lookup paths
look.lookupPath('.');
look.lookupPath('..');

// A lookup path to look in first,
// The default priority is 500, so
// any path with a lower priority value
// will be looked in first.  This will
// look two directories up before
// looking in the next two
look.lookupPath('../..', 100);

// Check if a file exists
look.exists('package.json', function(fullPath) {
	// The full path to the resolved package.json
	// Ex: /Users/you/your-project/package.json
	if (fullPath) {
		console.log('Yeah, found it: ' + fullPath);
	} else {
		console.error('Could not fine file');
	}
});

// Read a file content
look.readFile('package.json', function(err, content, fullPath) {
	// Check for errors
	if (err) {
		console.error('Either the file was not found or is not readable');
		return;
	}

	// Use the content
	var pkg = JSON.parse(content);
	console.log('Version: ' + pkg.version);
});

// Require a file
look.require('index.js', function(err, module, fullPath) {
	// Check for errors
	if (err) {
		console.error('Either it did not exist, or failed to be required');
		return;
	}
	
	// Use the module
	module.someFunc();
});

// Require a module, sync
var m = look.requireSync('index.js');
if (!m) {
	// Module not found
} else {
	// Do something with the module
}

// Require all files the directores
look.requireAll(function(modules) {

	// Modules is a hash of resolved paths to 
	// the required content of the module:
	// {
	//   '/full/path/to/file.js': [Function]
	//   '/full/path/file.js': [Function]
	// }
	
});

// Try for a file name in each lookup path
look.tryFiles([
	'home.html',
	'index.html'
], function(content, filepath) {
	
	// Looks for the first file, home.html, in each path, 
	// if it was not found, it moves on to index.html
	// The content and filepath returned are the first
	// file found that matched the filemname

});