# read-file-relative

> Read files with path relative to the current module without annoying boilerplate code

Latest version **1.2.0** (published 2015-10-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install read-file-relative
pnpm add read-file-relative
yarn add read-file-relative
bun add read-file-relative
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2015-10-06 |
| First published | 2015-10-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Ivan Nikulin |
| Maintainers | inikulin |
| Keywords | read, file, relative, path |

## Links

- npm: https://www.npmjs.com/package/read-file-relative
- Repository: https://github.com/inikulin/read-file-relative
- Issues: https://github.com/inikulin/read-file-relative/issues
- npm.io page: https://npm.io/package/read-file-relative

## Dependencies (1)

- [callsite](https://npm.io/package/callsite.md) ^1.0.0

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 1.2.0 (latest) — 2015-10-06
- 1.1.0 — 2015-10-06
- 1.0.1 — 2015-10-05
- 1.0.0 — 2015-10-05

## README

# read-file-relative
[![Build Status](https://api.travis-ci.org/inikulin/read-file-relative.svg)](https://travis-ci.org/inikulin/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:
```js
var fs   = require('fs');
var path = require('path');

var data = fs.readFileSync(path.join(__dirname, '/my-awesome-file')).toString();
```

Now you can replace it with:
```js
var readSync = require('read-file-relative').readSync;

var data = readSync('/my-awesome-file');
```

That's it.

You want a plain buffer instead of string? No problem - just use optional second argument:
```js
var readSync = require('read-file-relative').readSync;

var buffer = readSync('/my-awesome-file', true);
```

You like it the async way (didn't you :wink:)? Do it this way:
```js
var read = require('read-file-relative').read;

read('/my-awesome-file', function(err, content) {
   ...
});
```

You can pass options or encoding like for regular `fs.readFile`:
```js
var read = require('read-file-relative').read;

read('/my-awesome-file', 'utf8', function(err, content) {
   ...
});
```

BTW, you can just convert given path to absolute:
```js
var toAbsPath = require('read-file-relative').toAbsPath;

var absPath = toAbsPath('/my-awesome-file');
```

## Install
```
npm install read-file-relative
```

## Author
[Ivan Nikulin](https://github.com/inikulin) (ifaaan@gmail.com)

---
_Source: https://npm.io/package/read-file-relative · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
