make-module-env
TypeScript icon, indicating that this package has built-in type declarations

1.1.2 • Public • Published

make-module-env

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

Usage

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

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.1.2
    3
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.1.2
    3
  • 1.1.1
    0
  • 1.1.0
    0
  • 1.0.1
    62
  • 1.0.0
    0

Package Sidebar

Install

npm i make-module-env

Weekly Downloads

47

Version

1.1.2

License

MIT

Unpacked Size

5.89 kB

Total Files

6

Last publish

Collaborators

  • suchipi