Skip to content
    Node.js SandboxWeb Worker · Node.js API shim
    Terminal Output
    Starting worker...
    Starting...
    © WebFiddle.xyz

    JavaScript Online Compiler for Node.js-Style Code

    This JavaScript online compiler runs your code in a Web Worker inside your browser and adds a small shim of Node.js-style globals: process, a minimal Buffer, global, module and a require function. Use it as a quick Node.js online compiler or JavaScript playground for trying async code, array and object transformations, JSON handling and modern syntax without installing anything. It is not a real Node.js process: there are no core modules such as fs or http, no npm packages, and the JavaScript engine is the one built into your browser, which is V8 in Chrome and Edge, SpiderMonkey in Firefox and JavaScriptCore in Safari. The list of limitations below spells out exactly what the shim covers.

    How to use the JavaScript online compiler

    1. Type or paste JavaScript into the editor. You can use await at the top level, because the sandbox wraps your script in an async function before running it.
    2. Press Run Code. The script is sent to a fresh Web Worker, so the editor stays responsive while it runs.
    3. Read the Terminal Output panel. console.log, console.info and process.stdout.write appear as normal text; console.warn, console.error and uncaught errors appear in red.
    4. If a script never finishes, for example because of an infinite loop, press Stop to terminate the worker.
    5. Press Share to copy a link with your code compressed into the URL.

    Features

    • Top-level await: the script body runs inside an async function
    • Node.js-style globals: process (env, argv, cwd, nextTick, exit, stdout.write), a minimal Buffer, global and module.exports
    • Worker APIs from the browser: fetch, setTimeout, setInterval, URL, TextEncoder, crypto and structuredClone
    • Runs off the main thread in a Web Worker, with a Stop button for runaway loops
    • Error output in red, kept separate from normal console.log output
    • A clean worker for every run
    • Share links that store the code in the URL

    What works and what doesn’t

    • This is not Node.js. Code runs in your browser's JavaScript engine, and there are no Node core modules or libuv event loop. Every require() call, including require("fs"), require("path") and require("http"), throws an error.
    • Static import and export statements are syntax errors, because the script runs through the Function constructor rather than as an ES module. Packages cannot be imported from npm or a CDN.
    • Buffer is a minimal stand-in: Buffer.from() accepts a string or an array of bytes, and toString() decodes UTF-8. Encodings such as base64 and hex, slicing, and the rest of the Buffer API are missing.
    • process.version, process.platform and process.env hold fixed placeholder values from the shim. They do not describe a real Node.js release, so do not use them to test version checks.
    • Objects passed to console.log are printed as JSON. Map and Set are converted to plain objects and arrays, so output does not look exactly like Node's util.inspect.
    • fetch works only with URLs that allow cross-origin requests (CORS), because the request is made by your browser. There is no way to start an HTTP server.
    • Callbacks from timers that are not awaited can print after the run is marked finished. The next run starts a new worker, which discards them.

    Example programs

    Top-level await with Promise.all

    Two simulated API calls start together and are awaited at the top level of the script. Because they run concurrently, the total wait is set by the slower call, not the sum of both. Expected output: "Grace has 2 posts", then "both resolved after about 500 ms".

    const delay = (ms, value) => new Promise((resolve) => setTimeout(resolve, ms, value));
    
    const started = Date.now();
    const [user, posts] = await Promise.all([
      delay(300, { id: 7, name: "Grace" }),
      delay(500, ["Hello", "Async"]),
    ]);
    
    console.log(user.name, "has", posts.length, "posts");
    console.log(`both resolved after about ${Math.round((Date.now() - started) / 100) * 100} ms`);

    Grouping records with reduce

    A common data-shaping task: total each customer's orders with reduce and the nullish coalescing operator. Objects passed to console.log print as indented JSON, so the first line of output is {"ana": 162.5, "ben": 19.99} spread over four lines, followed by one padded line per customer.

    const orders = [
      { id: 1, customer: "ana", total: 42.5 },
      { id: 2, customer: "ben", total: 19.99 },
      { id: 3, customer: "ana", total: 120 },
    ];
    
    const totals = orders.reduce((acc, { customer, total }) => {
      acc[customer] = (acc[customer] ?? 0) + total;
      return acc;
    }, {});
    
    console.log(totals);
    for (const [name, sum] of Object.entries(totals)) {
      console.log(`${name.padEnd(5)} ${sum.toFixed(2)}`);
    }

    What the Node.js shim provides

    Prints the emulated process values, round-trips a string through the minimal Buffer, and shows the error that every require() call raises. console.error output is shown in red, and the script carries on afterwards, which is why the fetch check still prints true.

    console.log("platform:", process.platform);
    console.log("env:", process.env);
    console.log(Buffer.from("héllo").toString());
    
    try {
      require("fs");
    } catch (error) {
      console.error(error.message);
    }
    
    console.log("fetch available:", typeof fetch === "function");

    Frequently asked questions

    Is this a real Node.js online compiler?

    No. It is a Node.js-style shim, not a Node.js process. Your code runs in a Web Worker using the JavaScript engine built into your browser, with small stand-ins for process, Buffer, global and module. Node core modules, npm packages and native add-ons are unavailable, so use it for language-level JavaScript rather than server code.

    Can I use require, import or npm packages?

    No. require() exists only so scripts fail with a clear message: every call throws an error. Static import and export statements are syntax errors, because the code is run through the Function constructor instead of being loaded as an ES module. There is no install step, so npm packages cannot be added.

    Does top-level await work when I run JavaScript online here?

    Yes. The sandbox wraps your whole script in an async function before running it, so you can await promises at the top level, including Promise.all, timers and fetch calls. The run is marked finished when that function settles; callbacks from timers you did not await can still print after that.

    Which JavaScript features and APIs can I use?

    Anything your browser supports inside a Web Worker: modern syntax such as optional chaining, classes, private fields and async iterators, plus APIs like fetch, URL, TextEncoder, crypto and structuredClone. There is no DOM, because workers have no window or document, and results can differ slightly between Chrome, Firefox and Safari.

    How do I stop an infinite loop?

    Press Stop. The script runs in a Web Worker, so a loop that never ends does not freeze the editor, and Stop terminates that worker immediately and starts a clean one. Anything printed before you stopped it stays in the output panel, which helps you see how far the script got.

    Does this online JavaScript compiler send my code to a server?

    No. The code runs in a worker inside your own browser tab and is not uploaded to WebFiddle. It leaves your device only if your script calls fetch itself, or when you press Share and send someone the link, which stores the code compressed in the URL.

    Embed this sandbox

    Paste this iframe into any web page and readers can run code without leaving it. The snippet travels in the URL, so there is nothing to host and no account to create. Open the sandbox, write your example, press Share, then append that link’s query string to the embed URL to preload it.

    <iframe src="https://webfiddle.xyz/embed/javascript" width="100%" height="480" loading="lazy"
            style="border:1px solid #ddd;border-radius:8px"
            title="WebFiddle javascript sandbox"></iframe>
    Preview the embed

    Related articles

    Related sandboxes

    Official documentation