Online JavaScript Compiler

Run JavaScript in your browser's own engine, with stdin, Node-style console output and exit codes. No Node.js server, and nothing is uploaded.

Runs in your browser · Nothing uploadedFree · No sign-upYour browser’s JavaScript engine

Start from an example

main.js

Standard input (stdin)

Output

Nothing has run yet

Press Run to see what the program prints, or load one of these:

Embed this compiler

Paste this into your page. Visitors run code in their own browser, and nothing is sent to us.

JavaScript, run by your own browser

No Node.js server sits behind this page. Your code runs in the JavaScript engine of the browser you are reading this in (V8 in Chrome and Edge, SpiderMonkey in Firefox, JavaScriptCore in Safari), inside a sandboxed Web Worker.

Output looks the way Node prints it, and the usual ways of reading input work: prompt(), require('readline') and require('fs').readFileSync(0) all read the stdin box.

At a glance
Engine
Your browser’s own
Download
None
Input
prompt(), readline, fs.readFileSync(0)
Modules
readline, fs (stdin only), util
Run limit
10 seconds
Output
Formatted like Node

What works and what does not

We ran every row of this table in the compiler before writing it down.

FeatureWorks?
console.log, console.error, console.group

Objects, Maps and Sets print Node-style, such as [ 1, 2, { a: 1 } ]. console.table prints the data, not a grid.

Yes
prompt() and readline()

Each call returns the next stdin line, or null once the box is empty.

Yes
require('readline') and require('fs').readFileSync(0)

Enough to paste most competitive-programming solutions unchanged.

Yes
Top-level await, Promises, setTimeout, setInterval

The run waits for the timers you started before it ends.

Yes
Unhandled promise rejections

Reported as Uncaught errors with exit code 1, as Node does.

Yes
process.exit(), process.exitCode, process.stdout.write()

The exit code shows up above the output.

Yes
import and export statements

Code runs as a script, not a module. Use require() for the three built-in modules.

No
npm packages and other Node modules

require('lodash') or require('path') throws Cannot find module.

No
document, window, alert, localStorage

The code runs in a Worker, which has no page attached.

No
fetch, XMLHttpRequest, WebSocket

The sandbox blocks every network request.

No

Why run JavaScript here

Output that reads like Node

Nested objects, Maps, Sets, BigInts and class instances print the way node main.js prints them, so what you see here matches what you see locally.

Stack traces point at your lines

Errors are trimmed to main.js:line:column, so the location matches the line numbers in the editor.

Nothing to download

The engine is already in your browser. In our tests, a loop of 50 million additions finished in about 60 ms in Chrome.

A fresh Worker every run

Globals and timers from the previous run are gone, because each run starts in a brand-new Worker.

Errors you will probably hit

Most failures here come from code written for Node or for a web page.

SyntaxError: Cannot use import statement outside a module

What it meansThe code uses import, but it runs as a plain script.

FixSwap import for require('readline'), require('fs') or require('util'). The compiler prints this hint too.

Error: Cannot find module 'lodash'

What it meansnpm packages are not available.

FixWrite the helper yourself, or paste in the one function you need.

ReferenceError: document is not defined

What it meansThere is no web page inside the Worker.

FixTry DOM code in the HTML Viewer and Editor on this site instead.

TypeError: Reduce of empty array with no initial value

What it meansreduce() ran on an empty array without a starting value.

FixPass one, as in list.reduce((a, b) => a + b, 0).

Stopped: the program ran for more than 10 seconds

What it meansAn endless loop, or a setInterval that is never cleared.

FixAdd an exit condition, or call clearInterval(id) when you are done.

How this Online JavaScript Compiler works

When you press Run, the page passes your code and stdin to a sandboxed frame that cannot see this site, your cookies or the network. That frame starts a new Web Worker, and your browser's own engine runs the code there.

There is nothing to download, so runs start right away. Console output is formatted the way Node formats it, timers and promises are allowed to finish, and the Worker is thrown away when the run ends.

How to use this Online JavaScript Compiler

1

Write your code

Start from the sample, pick an example above the editor, or paste your own.

2

Add stdin

One value per line. prompt() and readline() each take one line per call.

3

Run it

Press Run JavaScript or Ctrl+Enter, then read the output, exit code and time on the right.

Example Usage

With 5 7 in stdin, this reads both numbers and prints their sum.

Input
const [a, b] = require('fs').readFileSync(0, 'utf8').trim().split(' ').map(Number); console.log(a + b);
Output
12

Frequently Asked Questions

Is this Node.js?
No. It is your browser's JavaScript engine, so language features match your browser version. For input and output you get prompt(), require('readline'), require('fs').readFileSync(0), util.inspect, util.format, process.exit, process.exitCode and process.stdout.write. Nothing else from Node is available.
How do I read input like on HackerRank or Codeforces?
Read everything at once with require('fs').readFileSync(0, 'utf8') and split it, or call prompt() once per line. The stdin box is handed over in full when the run starts.
Why does import fail?
The code runs as a classic script, where import and export are syntax errors. Use require() for readline, fs and util. If you want import syntax, the TypeScript compiler on this site accepts it.
Can I use npm packages?
No. There is no package installer and no network access, so require() only knows readline, fs and util.
Is my JavaScript code sent to a server?
No. It runs in your browser, inside a sandboxed frame and a Web Worker that cannot reach the network. Share links store the code after the # in the URL, and browsers never send that part to a server.
Why did my program keep running after the last line?
The run waits for timers you started. A setInterval that is never cleared keeps it alive until the 10-second limit. Clear it, or call process.exit().

Related Tools

Comments

Comments are provided by Disqus, which sets cookies and processes data under its own privacy policy.

The Online JavaScript Compiler is maintained by CodeItBro. We aim to provide the best free developer tools on the web. If you have feedback or suggestions, please visit our contact page.

As featured on

CodeItBro - Free dev tools + practical guides to help you ship faster | Product HuntCodeItBro - Free Online Developer Tools badgeCodeItBro badgeFeatured on neeed.directory