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.
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:
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.
- 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.
| Feature | Works? | Details |
|---|---|---|
| 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 | Objects, Maps and Sets print Node-style, such as [ 1, 2, { a: 1 } ]. console.table prints the data, not a grid. |
| prompt() and readline() Each call returns the next stdin line, or null once the box is empty. | Yes | Each call returns the next stdin line, or null once the box is empty. |
| require('readline') and require('fs').readFileSync(0) Enough to paste most competitive-programming solutions unchanged. | Yes | Enough to paste most competitive-programming solutions unchanged. |
| Top-level await, Promises, setTimeout, setInterval The run waits for the timers you started before it ends. | Yes | The run waits for the timers you started before it ends. |
| Unhandled promise rejections Reported as Uncaught errors with exit code 1, as Node does. | Yes | Reported as Uncaught errors with exit code 1, as Node does. |
| process.exit(), process.exitCode, process.stdout.write() The exit code shows up above the output. | Yes | The exit code shows up above the output. |
| import and export statements Code runs as a script, not a module. Use require() for the three built-in modules. | No | Code runs as a script, not a module. Use require() for the three built-in modules. |
| npm packages and other Node modules require('lodash') or require('path') throws Cannot find module. | No | require('lodash') or require('path') throws Cannot find module. |
| document, window, alert, localStorage The code runs in a Worker, which has no page attached. | No | The code runs in a Worker, which has no page attached. |
| fetch, XMLHttpRequest, WebSocket The sandbox blocks every network request. | No | The sandbox blocks every network request. |
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
Write your code
Start from the sample, pick an example above the editor, or paste your own.
Add stdin
One value per line. prompt() and readline() each take one line per call.
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.
Frequently Asked Questions
Is this Node.js?
How do I read input like on HackerRank or Codeforces?
Why does import fail?
Can I use npm packages?
Is my JavaScript code sent to a server?
Why did my program keep running after the last line?
Related Tools
Online Syntax Highlighter
Highlight your code with syntax coloring for various languages. Generate HTML with inline styles or classes.
JS Formatter
Beautify JavaScript code.
JS Minifier
Minify JavaScript code for production.
HTML Viewer and Editor
Write HTML code and see real-time preview instantly. Great for testing snippets.
Regex Tester
Test and debug regular expressions with real-time match highlighting.
TypeScript Compiler
Write TypeScript, compile it with the real TypeScript compiler and run it online. Everything happens in your browser, so your code is never uploaded.
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.

