# required-path

> Prepare path for require

Latest version **1.0.1** (published 2017-02-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install required-path
pnpm add required-path
yarn add required-path
bun add required-path
```

## 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.0.1 |
| Published | 2017-02-15 |
| First published | 2017-02-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Vasiliy Loginevskiy |
| Maintainers | yeti-or |
| Keywords | path, require, relative fix |

## Links

- npm: https://www.npmjs.com/package/required-path
- Repository: https://github.com/Yeti-or/required-path
- Homepage: https://github.com/Yeti-or/required-path#readme
- Issues: https://github.com/Yeti-or/required-path/issues
- npm.io page: https://npm.io/package/required-path

## 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.0.1 (latest) — 2017-02-15

## README

required-path
=============

Handy helper to prepare your string for require().

[![NPM Status][npm-img]][npm]
[![Travis Status][test-img]][travis]
[![Windows Status][appveyor-img]][appveyor]
[![Coverage Status][coverage-img]][coveralls]
[![Dependency Status][dependency-img]][david]

[npm]:            https://www.npmjs.org/package/required-path
[npm-img]:        https://img.shields.io/npm/v/required-path.svg

[travis]:         https://travis-ci.org/Yeti-or/required-path
[test-img]:       https://img.shields.io/travis/Yeti-or/required-path.svg?label=tests

[appveyor]:       https://ci.appveyor.com/project/Yeti-or/required-path
[appveyor-img]:   http://img.shields.io/appveyor/ci/Yeti-or/required-path.svg?style=flat&label=windows

[coveralls]:      https://coveralls.io/r/Yeti-or/required-path
[coverage-img]:   https://img.shields.io/coveralls/Yeti-or/required-path.svg

[david]:          https://david-dm.org/yeti-or/required-path
[dependency-img]: http://img.shields.io/david/yeti-or/required-path.svg

The emergence of this module is due to the fact that some methods of [path] module could return “un-required” path.

For example:

`path.relative('foo/bar', 'foo/baz.js')` will return `'../baz.js'`, and we could require it.

But `path.relative('foo', 'foo/bar/baz.js')` will return  `'bar/baz.js'`, and such path would cause error in require.

[path]: https://nodejs.org/dist/latest-v6.x/docs/api/path.html


Usage
-----

```js
var requiredPath = require('required-path');
var file = 'file.js';

try {
  require(file);
} catch(err) {
  err; → // "Error: Cannot find module 'file.js'"
}

var prepared = requiredPath(file);
require(prepared); → // now it's okay
```

License
-------

Code released under the [MIT License](LICENSE.txt).

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