require-resolve

Use the node way to resolve required path to absolute path.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
require-resolve
700.0.28 years ago8 years agoMinified + gzip package size for require-resolve in KB

Readme

require-resolve
!NPM versionnpm-imagenpm-url !Build Statustravis-imagetravis-url !Dependency Statusdaviddm-urldaviddm-image !Code Climateclimate-imageclimate-url !Coverage Statuscoveralls-imagecoveralls-url
Use the node way to resolve required path to absolute path.
The node way

Install

$ npm install --save require-resolve

Usage

var requireResolve = require('../'),
  path = require('path');

// Resolve a absolute file
console.log(requireResolve(__filename));

// Resolve a relative file
console.log(requireResolve('./example/simple.js', path.dirname(path.dirname(__filename))));


// output:
/*
{
  src: '/Users/{your_name}/Workspace/require-resolve/example/simple.js',
  pkg: {
    name: 'require-resolve',
    version: '0.0.1',
    main: 'src/require-resolve.js',
    root: '/Users/{your_name}/Workspace/require-resolve'
  }
}
*/


// Resolve a node module file
console.log(requireResolve('glup', __filename));
console.log(requireResolve('glup/taskTree', __filename));

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using gulp.

License

Copyright (c) 2015 Zhonglei Qiu. Licensed under the MIT license.