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

modified

v2.1.13

Published

Modified is a simple request client to deal with http local caches.

Downloads

61

Readme

modified NPM version Build Status Dependency Status

Modified is a simple request client to deal with http local cache.

Modified implemented last-modified, if-modified-since, etag, if-none-match of HTTP specifications.

Synopsis

Modified is built upon request and flavors it with cache support, so if you are familiar with request, you are almost ready to use modified.

var modified = require('modified');
var request = modified(options); // Then use it almost the same as request

request('http://google.com/doodle.png').pipe(fs.createWriteStream('doodle.png'));

Usage

If your server supports etag, or checks the if-modified-since header, modified will manage the local cache for you.

Specify the cache routing

If options.cacheMapper is not specified, caches will be saved into '~/.node_modified/' directory by default.

But you can do it yourself for better control.

var request = modified({
	cacheMapper: function(options, callback){
		// your code...
		callback(
			null, 
			path.join(
				pathToSaveNpmCache,
				url.parse(options.uri).pathname,
				'couchdb-document.json'
			)
		);
	}
});

request({
	method: 'GET',
	url: 'http://registry.npmjs.org/modified'
	
}, function(err, res, body){
	// ...
})

cache_file

String

The file path of the local cache to save response body according to a specific request. (Response headers will be saved into cache_file + '.modified-headers.json')

If you don't want modified to cache for a certain request, cache_file should be set to null

{
	cacheMapper: function(options, callback){
		var path = url.parse(options.url).pathname;
		
		if (path) {
			// 'http://xxx.com/abc/' -> '/abc'
			path = path.replace(/\/$/, '');
			
			callback(
				null, 
				// Where the cache should be saved.
				path.join(__dirname, 'cache', path)
			);
		
		} else {
			callback(null, null);
		}
	}
}

With options.cacheMapper, you could specify the paths where the cache will be saved.

Programmatical APIs

var request = modified(options);
  • options Object
    • cacheMapper function() Which is described above

request(options, callback)

modified(options) returns a function which acts nearly the same as request;

Returns

request(options, callback) returns an instance of modified.Modified which is a sub-class of Readable Stream.

A instance of Modified is an EventEmitter with the following extra event(s):

Event: 'complete'

Emitted when all the request process is complete, after the execution of user callback (the one of request(options, callback)).

Release History

  • 2.0.0 - Completely redesigned.

  • 1.1.0 - Modified instances are streams now. You can use modified to fetch binary files.

  • 1.0.0 - Initial release