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 🙏

© 2024 – Pkg Stats / Ryan Hefner

epr

v1.0.0

Published

A tool for making node require paths nicer

Downloads

7

Readme

EPR travis status

epr lets you use nicer require paths in your node programs. It lets you change code like this:

var module1 = require('../../../modules/module1'),
    module2 = require('./another/path/module2')

to

var module1 = require('module1'),
    module2 = require('module2')

How do you install it?

npm install -g epr

How do you use it?

Add an epr key to your package.json:

{
  "epr": {
    "module1": "lib/modules/module1"
  }
}

and run epr:

epr

epr will create symlinks in node_modules/ for each attribute in your epr object. Normal node rules follow, so you can add a package.json file for each of your directories to point to a main, or you can just use it as a shortcut:

var module1 = require('module1'),
// or
    module2 = require('module1/module2')

to set this up for deployments, call epr in your postinstall script

Any advice?

There are several ways you can use epr, you can link to individual modules, or you can link to directories that contain several modules. In either case I'd recommend linking to directories rather than specific files in either case. That makes them easier to later split out to external packages if you want to.

So if you are linking to an individual module, at say lib/modules/mymodule, just add "mymodule":"lib/modules/mymodule". This is best if you've got some sort of code that could be an external module, but you want to keep it internal for whatever reason.

If you've got a directory that contains modules of a particular type, say a "modals" directory, you can link to that by adding "modals": "lib/modals", and can be required with something like require('modals/user')

Lastly you could just link to lib/ or wherever else you store most your code.

Does it do anything else?

Sure,

  • epr clean: delete all symlinks that are not in package.json
  • epr empty: delete all symlinks in node_modules

can I use it from javascript?

Sure,

var epr = require('epr')
epr.entangle(process.cwd(), {module1: 'lib/module1'}) // create symlinks
epr.clean(process.cwd(), {module1: 'lib/module1'}) // same as epr clean
epr.empty(process.cwd()) // same as epr empty

All epr api functions can either take a standard node callback or return a promise

epr.entangle(process.cwd(), {module1: 'lib/module1'}, function(err){
  if(err) {
    console.error(err)
  } else {
    console.log('success!')
  }
})

epr.entangle(process.cwd(), {module1: 'lib/module1'}.then(function(){
  console.log('success!')
}, function(err){
  console.error(err)
})

I'd like to make a change

See contributing

What's with the name?

EPR is a reference to the Einstein-Podolsky-Rosen thought experiment which was the origin of the concept of entanglement in quantum mechanics, and the term "spooky action at a distance".

OS support

epr will definitely run under any unix, but it has not been tested under windows. Any testing or PRs for windows support would be greatly appreciated. It has specifically been tested to run in heroku.