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

fsplusgit

v0.2.0

Published

Wrap node.js' fs module and expose the contents of git repositories

Readme

FsPlusGit

An fs-compatible module compatible that exposes the contents of git repositories (including bare ones) inside virtual gitFakeFs folders.

var FsPlusGit = require('fsplusgit'),
    fsPlusGit = new FsPlusGit(require('fs'));

fsPlusGit.readFile('/path/to/repo.git/gitFakeFs/HEAD/fileAtTheRootOfTheRepo.txt', 'utf-8', function (err, contents) {/*...*/});
fsPlusGit.readFile('/path/to/repo.git/gitFakeFs/index/fileAtTheRootOfTheRepo.txt', 'utf-8', function (err, stagedContents) {/*...*/});
fsPlusGit.readdir('/path/to/repo.git/gitFakeFs/branches/', function (err, branchNames) {/*...*/});
fsPlusGit.readdir('/path/to/repo.git/gitFakeFs/tags/', function (err, tagNames) {/*...*/});
fsPlusGit.readdir('/path/to/repo.git/gitFakeFs/tags/foo/', function (err, fileNamesAtTheRootInFoo) {/*...*/});

All other method calls are proxied to the wrapped fs module, so any operation happening outside the gitFakeFs folders should work as usual.

There's also a special folder containing all the files and directories that have staged changes. This is useful in a pre-commit hook scenario where you might want to only lint the files that actually have changes:

fsPlusGit.readdir('/path/to/repo.git/gitFakeFs/changesInIndex/', function (err, entriesWithChangesInIndex) {/*...*/});
fsPlusGit.readFile('/path/to/repo.git/gitFakeFs/changesInIndex/fileWithStagedChanges.txt', 'utf-8', function (err, stagedContents) {/*...*/});

The indexOrWorkingCopy folder has the contents of the index shadowed by the untracked files in the working copy.

You can also patch the fs module in-place to make every other module instantly capable of getting to the contents of your git repositories. Just make sure to do it before any other module might grab a reference to an fs method:

require('fsplusgit').patchInPlace(require('fs'));

require('glob')('**/*', {cwd: '/path/to/repo.git/gitFakeFs/', mark: true}, function (err, fileNames) {
    if (err) throw err;
    console.log(fileNames);
});

which will produce something like:

[ 'HEAD/',
  'HEAD/fileStagedForDeletion.txt',
  'HEAD/foo.txt',
  'HEAD/subdir/',
  'HEAD/subdir/quux.txt',
  'branches/',
  'branches/master/',
  'branches/master/fileStagedForDeletion.txt',
  'branches/master/foo.txt',
  'branches/master/subdir/',
  'branches/master/subdir/quux.txt',
  'index/',
  'index/foo.txt',
  'index/stagedFile.txt',
  'index/subdir/',
  'index/subdir/stagedFileInSubdir.txt',
  'indexOrWorkingCopy/',
  'indexOrWorkingCopy/foo.txt',
  'indexOrWorkingCopy/fileStagedForDeletion.txt',
  'indexOrWorkingCopy/stagedFile.txt',
  'indexOrWorkingCopy/subdir/',
  'indexOrWorkingCopy/subdir/stagedFileInSubdir.txt',
  'changesInIndex/',
  'changesInIndex/stagedFile.txt',
  'changesInIndex/subdir/',
  'changesInIndex/subdir/stagedFileInSubdir.txt',
  'commits/',
  'commits/019433c0486da194b36a8da59910316ad704accd/',
  'commits/019433c0486da194b36a8da59910316ad704accd/foo.txt',
  'commits/019433c0486da194b36a8da59910316ad704accd/fileThatOnlyExistedInTheFirstCommit.txt',
  'commits/a1410fe23cc0c126d5546a366545a88e1d649759/',
  'commits/a1410fe23cc0c126d5546a366545a88e1d649759/fileStagedForDeletion.txt',
  'commits/a1410fe23cc0c126d5546a366545a88e1d649759/foo.txt',
  'tags/theFirstCommit/',
  'tags/theFirstCommit/foo.txt',
  'tags/theFirstCommit/fileThatOnlyExistedInTheFirstCommit.txt'

Limitations

The synchronous fs operations aren't supported inside the gitFakeFs folders due to limitations in the underlying libraries. If you need to make this work (eg. with third party code that uses readFileSync, such as the less compiler), you can wrap FsPlusGit in a cachedfs and make sure that you have read the files that you need to access before passing on control to the code that needs the synchronous operations to work:

var fs = require('fs'),
    glob = require('glob'),
    async = require('async');
require('fsplusgit').patchInPlace(fs);
require('cachedfs').patchInPlace(fs);

glob('/path/to/repo.git/gitFakeFs/HEAD/**/*.less', {stat: true}, function (err, lessFileNamesInHead) {
    if (err) throw err;
    async.each(lessFileNamesInHead, fs.readFile, function (err) {
        if (err) throw err;
        // Now it's safe to require('fs').readFileSync() and .stat() any .less file in repo.git/gitFakeFs/HEAD/

        require('less').render(fs.readFileSync(lessFileNamesInHead[0], 'utf-8'), function (err, cssText) {
            // ...
        });
    });
});

Implementation

Uses gitfakefs, which in turn uses nodegit to do the actual reading from git repositories.

Installation

Make sure you have node.js and npm installed, then run:

npm install fsplusgit

License

3-clause BSD license -- see the LICENSE file for details.