read-file-relative
Read files with path relative to the current module without annoying boilerplate code
Well, I've expected @sindresorhus has a module for this, but he didn't.
What's going on?
If you have code like this:
var fs = ;var path = ; var data = fs;
Now you can replace it with:
var readSync = readSync; var data = ;
That's it.
You want a plain buffer instead of string? No problem - just use optional second argument:
var readSync = readSync; var buffer = ;
You like it the async way (didn't you 😉)? Do it this way:
var read = read; ;
You can pass options or encoding like for regular fs.readFile
:
var read = read; ;
BTW, you can just convert given path to absolute:
var toAbsPath = toAbsPath; var absPath = ;
Install
npm install read-file-relative