userland.run70Try the demo
Example · hello-node

Hello, Node.js — in the browser

node · host JS engine

The smallest useful Node.js program: count the primes below 60 000 and print what it ran on. No packages, no build step — one file written into the in-memory filesystem and run with nano.node().

The sample runs on the host JS engine (the node runner, nodert), which is fast and reports process.arch as x64 for package compatibility. The same file also runs unmodified on the RISC-V VM with the real riscv64 Node.js v25.4.0 binary from the catalog — slower, but byte-for-byte upstream Node; it then reports riscv64. Node.js in the browser runs both side by side.

Run it

Node.js

Count primes with Node.js

Edit the program and run it again — it executes in this tab with nano.node() on the host JS engine.

javascript
// Pure Node.js — no dependencies. The same file runs on either Node engine:
//   • the host JS engine (nodert) — fast; reports process.arch "x64"
//   • the RISC-V VM (the real riscv64 Node ELF) — slow; reports "riscv64"
const t0 = Date.now();
let primes = 0;
for (let n = 2; n < 60000; n++) {
  let isPrime = true;
  for (let d = 2; d * d <= n; d++) {
    if (n % d === 0) {
      isPrime = false;
      break;
    }
  }
  if (isPrime) primes++;
}
console.log("node     :", process.version);
console.log("platform :", process.platform, process.arch);
console.log("primes   :", primes, "below 60000");
console.log("took     :", Date.now() - t0, "ms");
loading…
Expected output
node     : v25.4.0
platform : linux x64
primes   : 6057 below 60000
took     : 4 ms

How it runs

  1. createNano({ engines: { node: "host" } }) boots the kernel and the RISC-V VM (console.wasm) — on your first Run, not on page load.
  2. The program is written to the VFS with nano.fs.writeFile().
  3. nano.node([file]) routes it to the host-engine Node tier and streams stdout into the pane.

Source

From demos/hello-node/.

index.js
javascript
// Pure Node.js — no dependencies. The same file runs on either Node engine:
//   • the host JS engine (nodert) — fast; reports process.arch "x64"
//   • the RISC-V VM (the real riscv64 Node ELF) — slow; reports "riscv64"
const t0 = Date.now();
let primes = 0;
for (let n = 2; n < 60000; n++) {
  let isPrime = true;
  for (let d = 2; d * d <= n; d++) {
    if (n % d === 0) {
      isPrime = false;
      break;
    }
  }
  if (isPrime) primes++;
}
console.log("node     :", process.version);
console.log("platform :", process.platform, process.arch);
console.log("primes   :", primes, "below 60000");
console.log("took     :", Date.now() - t0, "ms");
package.json
json
{
  "name": "nano-hello-node",
  "version": "1.0.0",
  "private": true,
  "description": "Pure Node.js, zero dependencies — runs on the host engine or the RISC-V VM."
}

Further reading

Other examples