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

xreq

v2.0.0

Published

Extended require

Downloads

7

Readme

eXtended REQuest

Build Status

It requires files from the base path of your app and let you configure alias to other paths for faster refactoring. No more ../..!!

Features

  • No bootstrap required
  • No dependencies
  • Multiple alias support
  • Local path file resolution
  • Proxy support (mocks)

Installation

$ npm install xreq --save

Basic usage:

Use it in your modules:

//Current js file at foo/bar/a.js
var xreq = require('xreq');
//Require a file at other/folder/b.js, only searh from the base path
var b = xreq('other/folder/b');

How it works

It searches the package.json of your project, and build routes from that point.

Custom paths

Add some custom paths at package.json

"xreq": {
	"server": "src/server",
	"services": "src/server/services",
	"models": "src/server/models",
	"test": "test"
}

Use it in your modules:

//Current js file at foo/bar/a.js
var xreq = require('xreq');
//Require a file at "src/server/services". Use "service" alias as in the xreq
var AService = xreq.services('AService'); 
// That is better than require('../../src/server/services/AService');

Path resolution

Add a second parameter with value true

var xreq = require('xreq');

// Print the base location, the folder where the xreq file resides.
console.log(xreq('.', true)); 

// Print the complete path to file a.hbs
console.log(xreq('a.hts', true)); 

// It works the same way for aliases
console.log(xreq.templates('products.hts', true)); 

This method is quite useful for resolve template location or other static files in the local application.

Proxies

Adding a proxy to 'xreq'

xreq(function (file) {
	return require('another_folder/' + file);
});
The following line use the proxy function.
var bar = xreq('foo.js');

If the proxy function returns a falsy value the resolution continues normally.

Removing the proxy

xreq(null);