Have ideas to improve npm?Join in the discussion! »

npm-file

1.0.0 • Public • Published

npm-file experimental

Specify a path within an npm package: download and extract it, returning a local path for reading.

Usage

NPM

get = npmfile(cache, resolve)

Returns a function you can use to get files from packages on npm. Takes the following arguments, both of which are optional:

  • cache: the directory to store modules on the filesystem. Defaults to .npm-files.
  • resolve: a custom module resolution function. Defaults to resolve, and expects the same function signature.
var resolve  = require('glsl-resolve')
var cachedir = __dirname + '/.cache'
var getnpm   = require('npm-file')(cachedir, resolve)

get(package, version, filename, got)

Retrieves a file from npm. Takes the following arguments:

  • package: the name of the package on npm.
  • version: a semver version range. May also be a fixed version, or * or latest.
  • filename: the module in the package to retrieve. Uses the previously defined resolve function, so you can omit file extensions if you so please.
  • got(err, path): is called when complete, returning the file path of the target module.

License

MIT. See LICENSE.md for details.

Install

npm i npm-file

DownloadsWeekly Downloads

1

Version

1.0.0

License

MIT

Last publish

Collaborators

  • avatar