function-from-url
v1.1.0
Published
> Dynamically load JavaScript functions directly from a URL.
Downloads
8
Readme
function-from-url
Dynamically load JavaScript functions directly from a URL.
function-from-url is a tiny Node.js module that fetches a JavaScript function from a URL and returns it as a callable function. Perfect for dynamically loading code at runtime.
🚀 Installation
npm install function-from-url⚡ Usage
import { FunctionFromUrl } from 'function-from-url';
async function main() {
// URL containing the JavaScript function body
const url = 'https://example.com/my-function.js';
const myFunc = await FunctionFromUrl(url);
// Call the fetched function
myFunc();
}
main();✅ Example
Suppose the content at https://example.com/hello.js is:
console.log('Hello from a remote function!');Then:
import { FunctionFromUrl } from 'function-from-url';
const func = await FunctionFromUrl('https://example.com/hello.js');
func(); // Prints: Hello from a remote function!