Welcome to XCODX Online Compiler
Quick Start:
Ctrl+Enter Run code
Ctrl+S Save / Download
Ctrl+L Clear output
Select a language and start coding.
Welcome to XCODX Online Compiler
Quick Start:
Ctrl+Enter Run code
Ctrl+S Save / Download
Ctrl+L Clear output
Select a language and start coding.
Node.js is a runtime that executes JavaScript outside the browser, created by Ryan Dahl in 2009 by pairing Google's V8 engine with an event loop and non-blocking I/O. Instead of a page and a DOM, it exposes core modules for the file system, networking, streams, and process control, which made JavaScript a practical choice for servers, APIs, and command-line tools. Its single-threaded, event-driven model lets one process handle many concurrent connections without a thread per request. On XCODX, Node runs inside the Piston sandbox as plain server-side JavaScript: you get the standard library and stdin, but no network sockets and no browser objects like window or document. The runtime version is printed in the badge, and you can run code immediately without installing Node locally.
const readline = require('readline');
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
rl.question('Enter a number: ', (answer) => {
const n = parseInt(answer, 10);
let sum = 0;
for (let i = 1; i <= n; i++) sum += i;
console.log(`Sum from 1 to ${n} is ${sum}`);
rl.close();
});
Node.js is a natural fit for I/O-bound services such as web APIs, real-time apps, streaming, and command-line tools, where its non-blocking event loop handles many connections efficiently. Choose it when you want to use one language, JavaScript, across both client and server, or when you need a fast, lightweight runtime for glue code and tooling. Because it runs JavaScript on a single main thread, it is a poor fit for heavy CPU-bound computation that would block the event loop. In this sandbox there is no network access, so Node is used here for learning the language, stdin-driven programs, and standard-library exploration rather than running an actual server.
No. Only Node's built-in modules such as fs, path, readline, and os are available. There is no npm install and no network access, so external packages like Express or Lodash cannot be required.
Use the built-in readline module: create an interface over process.stdin and call rl.question, or listen for line events. On XCODX you type into the live terminal as the program runs, or provide the text through the Stdin Box; press Ctrl+D to close the stream.
You can write http.createServer code, but the sandbox has no inbound network access, so nothing can connect to it and there is no URL to open. Use this environment for stdin-driven programs and standard-library practice rather than live servers.
Both run JavaScript on the V8 engine, but Node adds server-side APIs for files, processes, and streams, and has no DOM. There is no window, document, or page to fetch into; instead you use core modules and console.log.
The main JavaScript runs on a single thread driven by an event loop, which is what lets one process handle many concurrent I/O operations without blocking. Heavy CPU-bound work still blocks that thread, so Node is best for I/O-bound rather than compute-bound tasks.
The exact runtime version is shown in the badge above the editor. The filesystem is reset on every run, so anything you write with fs disappears afterward and nothing is saved; copy any code you want to keep.
main.jsjavascriptrequire("readline") or process.stdinconsole.log("Hello from JavaScript!");
const name = "Developer";
console.log(`Welcome, ${name}!`);