🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

node-glob-import

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-glob-import

Allows you to load several files with a single import statement using a glob pattern.

latest
npmnpm
Version
0.1.0
Version published
Weekly downloads
4
33.33%
Maintainers
1
Weekly downloads
 
Created
Source

Import a list of files with a single import statement, using glob patterns.

Usage

First, you must enable the loader, which you can do by adding the --import=node-glob-import flag to node.

node --import=node-glob-import myscript.js

Then, you can make glob imports by adding the type: 'glob' attribute to the import:

// myscript.js
import somemodules from './somemodules/*.js' with { type: 'glob' };
import assert from 'node:assert';

// The imported value is an object where each key is a file found by the glob pattern...
assert(typeof somemodules === 'object');
assert('example.js' in somemodules);

// And the value for each key is a function that dynamically loads that file using `import()`.
const { default: example } = await somemodules['example']();
assert(example.foo === 'bar');
// somemodules/example.js
export default {
	foo: 'bar',
};

Keywords

glob

FAQs

Package last updated on 14 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts