JavaScript
console.log("Welcome to Online IDE!");
console.log("Start coding in JavaScript...");

Press Run or Ctrl ↵ to execute main.js.
Type program input here while it runs.

JavaScript

Online JavaScript Compiler

Your code runs with Node.js 24 as node main.js, and run settings switch to Node.js 22 or 26. readline reads what you type in the console while the program runs. This is Node, not a browser, so prompt(), alert() and document don’t exist.

Try it above

How JavaScript runs here

Versions
Node.js 22, 24 (default), 26
Run
node main.js
Limits per run
256 MB memory, 15 s of CPU time on half a core, 2 MB of output
Time
Up to 10 minutes a run (30 on a paid plan); waits 2 minutes for input (5 on a paid plan)
Sandbox
Each run gets its own Linux sandbox with no network access. Text files your program writes next to your code open as new tabs.

A program that reads input

readline/promises asks a question and waits for the answer with await:

JavaScript
const readline = require('node:readline/promises');

async function main() {
  const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
  const name = await rl.question('Your name: ');
  const line = await rl.question('Scores separated by spaces: ');
  rl.close();

  const scores = line.trim().split(/\s+/).map(Number);
  const average = scores.reduce((sum, s) => sum + s, 0) / scores.length;
  console.log(`${name}: ${scores.length} scores, average ${average.toFixed(1)}, best ${Math.max(...scores)}`);
}

main();
Terminal
$ node main.js
Your name: Ada
Scores separated by spaces: 72 95 88
Ada: 3 scores, average 85.0, best 95

rl.close() matters: without it the interface keeps listening, and the program sits waiting for more input after printing its result.

Reading input in Node.js

For a list of lines, loop over the interface with for await. The console can’t send end of input, so stop at an empty line:

JavaScript
const readline = require('node:readline');

async function main() {
  const rl = readline.createInterface({ input: process.stdin });
  const totals = new Map();
  console.log('Paste "item, amount" lines, then an empty line:');
  for await (const line of rl) {
    if (line.trim() === '') break;
    const [item, amount] = line.split(',').map(s => s.trim());
    totals.set(item, (totals.get(item) ?? 0) + Number(amount));
  }
  rl.close();
  for (const [item, sum] of totals) console.log(item.padEnd(8) + sum.toFixed(2));
}

main();
Terminal
$ node main.js
Paste "item, amount" lines, then an empty line:
coffee, 3.50
bread, 2.25
coffee, 3.50

coffee  7.00
bread   2.25
  • fs.readFileSync(0, 'utf8'), common in judge templates, reads until end of input. Here that never comes, so the program waits until the input wait in the table above runs out. The same goes for code that does its work in process.stdin.on('end').
  • prompt() is a browser function: in Node it fails with ReferenceError: prompt is not defined. Use rl.question().
  • Everything typed arrives as a string. Convert with Number(s), or split a line with line.trim().split(/\s+/).map(Number).

Several files: require and import

Files sit next to main.js. With ES modules, import names the file with its extension:

JavaScript
// utils.js
export const slug = (s) => s.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '');

// main.js
import { slug } from './utils.js';
console.log(slug('Hello, World!'));
Terminal
$ node main.js
hello-world
  • Node sees the import and export syntax and runs the files as ES modules, so a .js file needs no package.json or .mjs extension.
  • Leave out the .js and Node stops with Error [ERR_MODULE_NOT_FOUND]: Cannot find module, naming the path without the extension.
  • CommonJS works too: module.exports in utils.js and const { slug } = require('./utils'), where the extension is optional. A file uses one style or the other: require in a file that also has import fails with ReferenceError: require is not defined in ES module scope, you can use import instead.
  • Run starts the open tab unless Entry file in run settings names one, so set it to main.js while you edit utils.js.

What isn’t available

  • npm packages. There’s no npm install or node_modules, so require('lodash') stops with Error: Cannot find module 'lodash'. Node’s own modules all work: fs, path, readline, crypto, util, events, assert and the rest.
  • The browser. There’s no page, so document, window, alert() and localStorage are undefined, and HTML or CSS in a string prints as plain text.
  • Network access. fetch() exists in Node but fails, because runs are offline.

Errors you’re likely to see

  • “ReferenceError: prompt is not defined”: browser code. Read input with readline as above.
  • “ReferenceError: document is not defined”: DOM code needs a browser page, which doesn’t exist here. Test the logic with plain values and console.log().
  • “Error: Cannot find module 'lodash'”: an npm package. Write the helper yourself or use a built-in, such as structuredClone() for a deep copy.
  • “TypeError: Cannot read properties of undefined (reading 'length')”: the value before .length is undefined, often a misspelled property or an index past the end of an array.
  • “TypeError: Assignment to constant variable.”: a const was reassigned. Declare it with let.

Node prints where it happened as main.js:2:27, and that’s a link to the line. After a failed run, Fix with AI explains the error and proposes a change you review before it applies.

JavaScript behavior worth checking here

A line that surprises people new to JavaScript:

JavaScript
console.log(0.1 + 0.2, [10, 9, 1].sort(), "5" + 3, "5" - 3);
Terminal
$ node main.js
0.30000000000000004 [ 1, 10, 9 ] 53 2
  • 0.1 + 0.2 isn’t exactly 0.3 because numbers are binary floating point. Round for display with toFixed(2).
  • sort() with no argument compares numbers as strings, so 10 comes before 9. Sort numbers with sort((a, b) => a - b).
  • + joins when either side is a string, while - always converts to numbers.
  • Integers above Number.MAX_SAFE_INTEGER (2^53 - 1) lose precision. Use BigInt: 2n ** 64n prints 18446744073709551616n.
  • Newer built-ins work on every offered version: toSorted(), Object.groupBy() and the Set methods union() and intersection().

Questions

Does prompt() work?

No. prompt() belongs to browsers, and your code runs on Node.js. Use readline’s rl.question() to ask for input in the console.

Which Node.js version is it?

Node.js 24 by default. Run settings offer Node.js 22 and 26.

Can I use npm packages?

No, there’s no npm install. Node’s built-in modules such as fs, readline and crypto are all available.

Why does my judge template never finish reading input?

It reads all of stdin with fs.readFileSync(0) or waits for the end event, and the console can’t send end of input. Read line by line with readline and stop after a known count or an empty line.

Can I run HTML and browser JavaScript here?

No. There’s no page or DOM, only Node.js and a console, so document and window are undefined.

Is TypeScript supported?

Yes, on its own page: main.ts compiles with tsc and then runs on Node.js. See the online TypeScript compiler.