A lightweight Node.js utility to execute JavaScript from strings or remote URLs — inspired by Lua's loadstring()
.
- ✅ Run JavaScript from a string
- 🌐 Load & execute code from a remote URL
- 🧠 Smart
load()
function auto-detects string vs. URL - ✨ Zero Dependencies
- ⚡ Simple, async-friendly API
npm install loadstring
const { loadString } = require('loadstring');
// import { loadString } from 'loadstring';
loadString(`console.log("Hello from string!");`);
loadString(`
console.log("Line 1");
console.log("Line 2");
`);
const { loadStringFromURL } = require('loadstring');
// import { loadStringFromURL } from 'loadstring';
loadStringFromURL('https://example.com/script.js');
If https://example.com/script.js
contains:
console.log("🔥 Remote code executed!");
You’ll see:
🔥 Remote code executed!
const { load } = require('loadstring');
// import { load } from 'loadstring';
// Runs a code string
load('console.log("From string!")');
// Loads and runs from a remote URL
load('https://example.com/hello.js');
Executes a string of JavaScript code.
Fetches JavaScript code from a remote URL and executes it.
Smart loader — detects if the input is a URL and runs accordingly.
This module uses new Function()
under the hood.
❗️ Never run untrusted or user-generated input — this allows full code execution.
MIT