0.1.0 • Published 10 years ago
get-module-file v0.1.0
get-module-file
This module is a utility for finding the path to a file within an installed module.
Example
Let's assume you have the following project structure:
-- my_module
|
|
-- node_modules
| |
| |
| -- style_mod
| |
| |
| -- style.css
|
|
-- lib
|
|
-- foo.jsFor some reason your foo.js needs to read the contents of style.css. But
a module of assets usually cannot be required (e.g. concise.css).
On top of that, the node_modules directory may not be where you think if your
module is installed in another module; with npm3 the style_mod module could
be in the parent module's node_modules.
Solution: use get-file-module to find the file:
const gfm = require('get-file-module');
gfm.future(__dirname, 'style_mod', '/style.css')
.then(function(filePath) {
// read the file and do whatever is you need to do
});API
async(startDir, moduleName, filePath, callback)
startDir: the directory from which to start looking fornode_modulesmoduleName: the name of the module that contains the file you wantfilePath: relative path to the file from the module directorycallback: a function with parameterserrorandresolvedPath.
sync(startDir, moduleName, filePath)
startDir: the directory from which to start looking fornode_modulesmoduleName: the name of the module that contains the file you wantfilePath: relative path to the file from the module directory- returns:
falseon error (i.e. can't find file) or the resolved file path
future(startDir, moduleName, filePath)
startDir: the directory from which to start looking fornode_modulesmoduleName: the name of the module that contains the file you wantfilePath: relative path to the file from the module directory- returns: a
Promisethat has the resolved file path on resolution and anErroron rejection (couldn't find the file)
License
0.1.0
10 years ago