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

lomod

v1.1.0

Published

Local Module Require

Downloads

41

Readme

lomod

Loading modules from not only 'node_modules' but also 'lib' folders, which usually contains project's local modules.

Install

npm install lomod

Usage

project/
  + common/
  |  + local_modules/
  |     + common-util.js
  + app/
     + local_modules/
     |  + app-util.js
     + submod/
     |  + local_modules/
     |  |  + libdir/
     |  |  |  + dir-util.js
     |  |  + sub-util.js
     |  + test.js
     + package.json

app/submod/test.js

var lomod = require('lomod');

// use as a replacement of original require
var fs = lomod('fs');

var sutil = lomod('sub-util');
var dutil = lomod('libdir/dir-util');
var autil = lomod('app-util');
var cutil = lomod('common-util');

app/package.json

{
  "name": "proj-app",
  "version": "1.0.0",
  "localDependencies": [
    "../common"
  ]
}

Looking-up Modules

Any module identifier passed to lomod() will be tried on original require first.

If this failed, and the module identifier does not begin with '/', '../', or './', then lomod starts at the current directory, adds /LOCAL_MODULE_DIRNAME, and attempts to load the module from that location. (LOCAL_MODULE_DIRNAME could be 'local_modules' or 'lib' for default)

If it is not found there, then it moves to the parent directory, and so on, until the root of the tree is reached, or a package.json with property localDependencies was found (check the next chapter).

For example, if the file at '/home/ry/projects/foo.js' called lomod('bar.js'), then lomod would look in the following locations, in this order:

try to require('bar.js')
/home/ry/projects/local_modules/bar.js
/home/ry/local_modules/bar.js
/home/local_modules/bar.js
/local_modules/bar.js
/home/ry/projects/lib/bar.js
/home/ry/lib/bar.js
/home/lib/bar.js
/lib/bar.js

This is almost same with the original require, just consider it as you got two extra module directories beside 'node_modules'.

Local Module Dirs

Lomod find local modules in directories named 'local_modules' or 'lib' by default. You can customize these names if they didn't fit your need:

var lomod = require('lomod').in('lib', 'mylib')

Then lomod will find local modules in directories named 'lib' or 'mylib', the default directories 'local_modules' will be ignored.

You can also use empty string as dirname:

var lomod = require('lomod').in('')
var tools = lomod('local_modules/tools')

is equals to:

var lomod = require('lomod').in('local_modules')
var tools = lomod('tools')

Local Dependencies

A "localDependencies" property with string array value in package.json stop the recusive moving to parent directory. Instead of it, lomod start looking up from each path in this array.

For example, if the file at '/home/ry/projects/foo.js' called lomod('bar.js'), and the file at '/home/ry/package.json' contains localDependencies assigned ['/share', '/usr/share'], then lomod would look in the following locations, in this order:

try to require('bar.js')
/home/ry/projects/local_modules/bar.js
/home/ry/local_modules/bar.js    (go to localDependencies)
/share/local_modules/bar.js
/local_modules/bar.js
/usr/share/local_modules/bar.js
/usr/local_modules/bar.js
/local_modules/bar.js            (has been scaned, ignore)
/home/ry/projects/lib/bar.js     (continue with local module dir "lib")
....

Lomod ignored '/home/lib/bar.js' in this example. You can simply prevent it by append '..' to the localDependencies array.

Ignore Original Require

Lomod will try to load module by original require first. You can ignore this by use lomod.requireLocal and lomod.resolveLocal

project/
  + local_modules/
  |  + util.js
  + main.js

main.js

var sys_util = require('util');
var my_util  = lomod.requireLocal('util');
var my_util2 = require(lomod.resolveLocal('util'));

You can also specify a starting directory. Original require will also be ignored in this situation:

var util = lomod('util', '/opt/my_lib/');
// will be found in /opt/my_lib/local_modules/util

Support Other File Formats

Any format supported by original require will be inherited to lomod.

project/
  + node_modules/
  |  + res.yaml
  + local_modules/
  |  + lores.yaml
  + test.js

test.js

require('require-yaml');

var res = require('res');
var lomod = require('lomod'),
    lores = lomod('lores');

some format modules by olalonde

These modules support extra formats by adding handlers to require.extensions which is a deprecated feature in node's module system. Since the module system is locked, this feature will probably never go away but may have subtle bugs. Use on your own risk.