load-remote-module
v1.0.1
Published
Load JavaScript modules dynamically from remote URLs — safely, asynchronously, and with zero configuration.
Readme
load-remote-module
Load JavaScript modules dynamically from remote URLs — safely, asynchronously, and with zero configuration.
load-remote-module lets you fetch and execute remote ES modules at runtime.
Perfect for plugin systems, dynamic feature loading, micro‑frontends, or any scenario where your code needs to pull logic from the outside world.
✨ Features
- 🚀 Load ES modules from any URL
- 🔒 Isolated execution using native dynamic
import() - 🧩 Works with any module that exports functions, objects, classes, etc.
- ⏱️ Promise‑based API
- 🪶 Tiny & dependency‑free
📦 Installation
npm install load-remote-module🛠️ Usage
Basic Example
import loadRemoteModule from 'load-remote-module';
async function test() {
const mod = await loadRemoteModule('https://test.com/test');
console.log(mod.sayHello('Alice'));
}
test();What the remote module might look like
function sayHello(name) {
return `Hello, ${name}!`;
}
module.exports = { sayHello };📚 API
loadRemoteModule(url: string): Promise<any>
Loads a remote ES module and returns its exported object.
Parameters
| Name | Type | Description | |------|--------|------------------------------------------| | url | string | Full URL to the remote JavaScript module |
Returns
A Promise resolving to the module’s exports.
⚠️ Security Notes
Loading remote code always carries risk. You should only load modules from trusted sources and consider implementing:
URL allowlists
Integrity checks
Version pinning
Sandboxing strategies
🧪 Example Use Cases
Plugin systems
Dynamic feature flags
Remote configuration logic
Micro‑frontend architectures
A/B testing logic loaded on demand
📄 License
MIT — feel free to use it however you like.
