XCODX |

Node.js Online Compiler & Interpreter

Select Language
Online Code Compiler
Full HTML IDE
Py main.py
Program Output Ready
  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.
Success
Operation completed

About Node.js

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.

Hello World in Node.js

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();
});

When to use Node.js

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.

Common questions

Can I use npm packages like Express in the Node.js sandbox?

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.

How do I read input from stdin in Node.js?

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.

Can I build a web server here that I can visit in a browser?

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.

What is the difference between Node.js and browser JavaScript?

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.

Is Node.js single-threaded?

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.

What Node version does this run, and do files persist?

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.

How Node.js runs on XCODX

Sandbox filename
main.js
Entry point
single main source file
Editor grammar
javascript
Reading stdin
require("readline") or process.stdin
Input delivery
live WebSocket stream
Prompt flushing
flush manually before reading input
Compile limit
10 s
Run limit
3 s batch · up to 3 min live
Memory
256 MB per stage
Max source
50,000 characters

Default program on this page

console.log("Hello from JavaScript!");
const name = "Developer";
console.log(`Welcome, ${name}!`);