Skip to content

Node Runtime

The @ripl/node package is Ripl's server-side rendering entry point. It swaps the platform factory over to Node-compatible implementations — setTimeout for the animation frame, performance.now() for the clock, a monospace text metric, a process.stdout context — and re-exports everything from @ripl/core and @ripl/terminal, so a headless script builds scenes, runs a renderer and draws charts from a single import, with no DOM and no browser.

Installation

bash
npm install @ripl/node

Usage

Import @ripl/node at the top of your entry point to configure the runtime factory. This is equivalent to importing @ripl/web in a browser environment:

ts
import '@ripl/node';

import {
    createCircle,
    createContext,
    createRenderer,
    createScene,
    createTerminalOutput,
} from '@ripl/node';

// Create a terminal context bound to process.stdout
const output = createTerminalOutput();
const context = createContext(output);

// Use the scene and renderer as normal
const scene = createScene(context);
const renderer = createRenderer(scene);

renderer.start();

createCircle({
    fill: '#3a86ff',
    cx: context.width / 2,
    cy: context.height / 2,
    radius: 40,
}).render(context);

Factory Configuration

@ripl/node sets the following factory implementations:

Factory MethodNode Implementation
requestAnimationFramesetTimeout(cb, 16) (~60fps)
cancelAnimationFrameclearTimeout
nowperformance.now()
devicePixelRatio1
createContextCreates a TerminalContext with createTerminalOutput()
measureTextMonospace approximation (8px per character)
getDefaultStateSensible defaults for terminal rendering

createTerminalOutput()

Creates a TerminalOutput adapter backed by process.stdout:

  • write: writes ANSI escape sequences to stdout
  • columns / rows: reads terminal dimensions from process.stdout.columns and process.stdout.rows
  • onResize: listens for SIGWINCH signals to detect terminal resize events

Comparison with @ripl/web

@ripl/web@ripl/node
EnvironmentBrowserNode.js
RenderingCanvas 2D / SVGBraille characters (ANSI)
AnimationrequestAnimationFramesetTimeout(cb, 16)
InteractionMouse/pointer eventsNone
TextFull font metricsMonospace approximation
GradientsCSS gradient stringsSolid colors only
OutputDOM elementprocess.stdout / any TerminalOutput

Rendering Charts

Charts from @ripl/charts accept a terminal context as their target like any other context; see Server-Side Rendering for a complete headless charting example.