Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/joutvhu/import-by

Import a module using a string reference
https://github.com/joutvhu/import-by

import module nodejs parent-dirname string-ref

Last synced: 16 days ago
JSON representation

Import a module using a string reference

Awesome Lists containing this project

README

        

# import-by

Import a module using a string reference

## Installation

Install using `pnpm`:
```shell
pnpm add import-by
```

Or `yarn`:
```shell
yarn add import-by
```

Or `npm`:
```shell
npm i import-by
```

## Usage

See the following example to understand how to use it:

- Create a file called is `detail.js`.
```js
// detail.js
module.exports.beverage = {
id: 12,
name: 'coffee'
};
```

- And now, you can use `importBy` method to import the property from the `detail.js` file.
```js
const {importBy} = require('import-by');

const beverage = importBy('./detail#beverage');

const beverageName = importBy('./detail#beverage.name', __dirname);
```