# make-module-env

> Create exports, module, require, __filename, and __dirname variables for any path

Latest version **1.2.0** (published 2025-09-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install make-module-env
pnpm add make-module-env
yarn add make-module-env
bun add make-module-env
```

## Health

**Score 60/100 (C)** — status: stable.

Positive: has types; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2025-09-28 |
| First published | 2018-03-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Lily Skye |
| Maintainers | suchipi |

## Links

- npm: https://www.npmjs.com/package/make-module-env
- Repository: https://github.com/suchipi/make-module-env
- Homepage: https://github.com/suchipi/make-module-env#readme
- Issues: https://github.com/suchipi/make-module-env/issues
- npm.io page: https://npm.io/package/make-module-env

## Recent versions

- 1.2.0 (latest) — 2025-09-28
- 1.1.3 — 2024-05-07
- 1.1.2 — 2023-11-12
- 1.1.1 — 2023-11-12
- 1.1.0 — 2023-10-25
- 1.0.1 — 2018-03-25
- 1.0.0 — 2018-03-25

## README

# make-module-env

Create `exports`, `module`, `require`, `__filename`, and `__dirname` variables for any path

## Usage

```js
const makeModuleEnv = require("make-module-env");

const { exports, module, require, __filename, __dirname } = makeModuleEnv(
  "/Users/suchipi/Code/my-project/index.js"
);

// Use as normal
require.resolve("./package.json"); // resolves to /Users/suchipi/Code/my-project/package.json if it exists
```

## API Documentation

This module exports one function, `makeModuleEnv`. It should be called with the absolute path to a file, and it will return an object with `exports`, `module`, `require`, `__filename`, and `__dirname` properties that behave like the ones node would provide to that file. Note that the file at the path passed in does not need to exist, only the directories leading up to that file. So you can use eg. `path.resolve(__dirname, "fake-file.js")`.

## License

MIT

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