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 🙏

© 2026 – Pkg Stats / Ryan Hefner

rfile

v1.0.0

Published

Require a plain text or binary file in node.js

Readme

rfile

Build Status Dependency Status

require a plain text or binary file in node.js

Installation

$ npm install rfile

Usage

var rfile = require('rfile');

var text = rfile('./my-text-file.txt');
var mochaReadme = rfile('mocha/readme.md');
var mochaSource = rfile('mocha');
var image = rfile('image.png', {binary: true});

API

rfile(pkg, options)

Uses rfile.resolve (see below) to look up your file pkg. This means it supports all the same options as rfile.resolve. Having found the file, it does the following:

return options.binary ? read(path) : fixup(read(path).toString());

options.binary defaults to false and fixup removes the UTF-8 BOM if present and removes any \r characters (added to newlines on windows only).

rfile.resolve(pkg, options)

Internally, resolve is used to lookup your package, so it supports all the same options as that. In addition t defaults basedir to the directory of the function which called rfile or rfile.resolve.

The additional option exclude is useful if you wanted to create a wrapper arround this. It specifies the filenames not to consider for basedir paths. For example, you could create a module called ruglify for requiring and minifying JavaScript in one go.

ruglify.js

var rfile = require('rfile');
var uglify require('uglify-js').minify;

module.exports = ruglify;
function ruglify(path, options) {
  return minify(rfile.resolve(path, {exclude: [__filename]}), options).code;
}

From resolve

  • opts.basedir - directory to begin resolving from (defaults to __dirname of the calling module for rfile)
  • opts.extensions - array of file extensions to search in order (defaults to ['.js', '.json'] for rfile)
  • opts.readFile - how to read files asynchronously
  • opts.isFile - function to asynchronously test whether a file exists
  • opts.packageFilter - transform the parsed package.json contents before looking at the "main" field (useful for browserify etc.)
  • opts.paths - require.paths array to use if nothing is found on the normal node_modules recursive walk (probably don't use this)

Notes

One of the interesting features of this is that it respects the main field of package.json files. Say you had a module called foo, you could have a package.json like:

{
  "name": "foo",
  "version": "1.0.0",
  "main": "./foo"
}

You might then have a foo.js file, containing the JavaScript code of the module, and a foo.css file containing the stylesheet for the module when used in the browser. Using rfile you could load the css by simply calling:

rfile('foo', {extensions: ['.css']});

License

MIT