Examples
NodeAmiga ships with 44 demo scripts in the examples/
directory. Every feature has at least one example. Below they're
grouped by topic — read the source of any file that interests you.
Running an example
NodeAmiga examples/hello.js
NodeAmiga examples/weather.js Warsaw
NodeAmiga examples/gui_window.js
Most examples print usage help if you run them with -h or
without required arguments.
Categories on this page
Language basics (12 examples)
hello.js — Hello world
Prints greeting plus platform info via process.platform, process.arch, process.pid, process.cwd(), process.argv, process.env, and Date.
fibonacci.js — Benchmarks
Three Fibonacci implementations (recursive, iterative, memoized via IIFE closure) timed with Date.now(). Good reference for loops, closures, and arrow functions.
closures.js — Closure patterns
Five patterns: a function factory, a counter with private state, the IIFE module pattern (simulating Amiga chip RAM), partial application, and memoization.
classes.js — ES6 classes
Three-level inheritance (AmigaChip → CustomChip → EnhancedChip) demonstrating extends, super, static methods, instanceof. Includes a simple Computer class with toString.
array_fun.js — Array higher-order methods
Operates on a dataset of classic Amiga games: map, filter, find, sort (with spread copy), reduce (average, counts, groupings). Ends with a chained filter→sort→map→forEach.
calculator.js — Expression parser
Recursive-descent arithmetic calculator in pure JS. Supports + - * / % ^, variables, assignment, Math.* functions, parentheses. Can be invoked from the command line: NodeAmiga calculator.js "2+3*(4-1)".
todo_app.js — CLI TODO list
Simple CLI with subcommands: add, list, done, remove, clear. Persists to RAM:todo.json as pretty-printed JSON.
json_db.js — JSON-backed DB
A minimal document database with collection(name) returning insert / find / findOne / update / remove / count / drop. Queries can be plain value matches or predicate functions.
regex.js — Regular expressions
Walks through email validation, exec with global flag and groups, String.match, replace, search, flag combinations, character classes, and the division-vs-regex disambiguation in the lexer.
events.js — EventEmitter
Basic on/emit, once, a subclass (AmigaHardware extends EventEmitter) with multiple event types, and listener removal.
promises.js — Promise basics
Construction, .then/.catch chaining, error propagation, Promise.all, Promise.race, Promise.resolve flattening.
timers.js — Timers
Chained setTimeout, a countdown with setInterval / clearInterval, periodic memory reporter, nested timer chain.
Files and data (6 examples)
file_io.js — Basic fs operations
Writes / reads / appends a text file in RAM:, checks stats with statSync, saves and loads JSON, renames, cleans up with unlinkSync.
buffer.js — Binary data
Creates buffers from strings and arrays, fills, copies, concatenates. Shows a mini binary protocol: createPacket/parsePacket with magic byte, type, BE length, payload.
streams.js — Streams and pipes
Constructs Readable, Writable, and Transform streams, wires them with pipe(). Includes a line-counter Transform splitting on \n.
mini_grep.js — grep clone
Command-line grep with flags -i, -n, -c, -v. Runs in demo mode if no args. Multi-file support.
url_parser.js — URL / querystring
Parses URLs (url.parse(s, true)), formats them back, manipulates queries via querystring, resolves relative URLs.
iff_info.js — IFF file inspector
Open any IFF/ILBM/8SVX file and dump its chunk structure. For images shows width/height/numPlanes/compression/palette; for audio shows sample rate, octaves, length.
Networking (7 examples)
Requires bsdsocket.library
All networking examples need a TCP/IP stack installed (Miami, Roadshow, AmiTCP, or similar). HTTPS additionally needs AmiSSL.
http_server.js — HTTP server
Routes: GET / → HTML landing page, GET /api/info → JSON with runtime/memory info, GET /api/stats → request count/uptime, POST /echo → echoes the request body, default → 404.
http_client.js — HTTP client
Companion to http_server.js. Demonstrates http.get, http.post with JSON body, status handling, 404 path.
weather.js — Weather for a city
Fetches wttr.in in JSON mode. Default city: London. Pass a name on the command line: NodeAmiga weather.js Warsaw.
download.js — Download a file
NodeAmiga download.js http://.../file.lha RAM:file.lha. Does HTTP GET, saves body via fs.writeFileSync, shows bytes saved.
myip.js — What's my IP
Tries three public IP services in sequence, stops on the first success. Uses JSON parsing.
nettime.js — Internet time
Hits time APIs over plain HTTP (falls back gracefully if they need HTTPS). Always prints local Date.now() so you can compare.
dns_lookup.js — DNS resolution
Shows both dns.resolveSync(host) and dns.lookup(host, cb). Pass a hostname as the argument.
readline_chat.js — Interactive input
Simple chat prompt using readline. Demonstrates both the on('line') and rl.question(cb) APIs. Commands: quit, history.
Intuition graphics (5 examples, low-level)
gui_hello.js — Simplest window
The absolute minimum: open a window, draw text, wait for close. Good starting point for graphics.
gui_demo.js — Mouse / keyboard handling
Window with drawing primitives. Click to draw filled circles in cycling colors; press C to clear, Esc to exit.
3d.js — Rotating wireframe cube
Proper 3D rotation matrices (X, Y, Z), perspective divide, screen projection. Uses XOR draw mode for flicker-free animation. --bench flag runs a 5000-frame benchmark.
3d_tunnel.js — Vortex tunnel
Concentric wobbling circles moving toward the viewer. Retro demoscene feel, ~60 lines.
pong.js — Bouncing ball
Ball bounces off window walls with XOR-draw for zero-flicker animation and waitTOF sync. Press Esc to exit.
GadTools GUI (8 examples, high-level)
gui_menu.js — Menus, file & font requesters
Window with Project/Edit menus, keyboard shortcuts, ASL file requester and font requester wired up.
gui_window.js — All widget kinds
Reference gallery: text, string, integer, checkbox, cycle, mx (radio), slider, scroller, number, listview (flex), buttons. Responsive layout with percent widths and bottom-anchored buttons.
gui_drawing.js — gui.gfx scenes
Four demo scenes switched via a cycle gadget: shapes (lines fan, rect, circle, ellipse, pixels, text), color bars with XOR-mode labels, starfield with nebula, 8×8 checkerboard. Responds to resize.
gui_calculator.js — 4×4 calculator
Buttons + display, + - × ÷ arithmetic. Keyboard input works too. Practical use of setDisabled and gadget value sync.
gui_keyboard_and_scrolls.js — Scrollable grid
Moving a cursor with arrow keys on a larger-than-viewport grid. Scrollers sync with cursor position. Click in the area gadget jumps to that cell.
gui_gfx_clock.js — Analog clock
Flicker-free analog clock. Only redraws hands on second change; full redraw on resize. Shows gfx.innerSize for responsive layout.
gui_translator.js — Google Translate client
Two text fields, two language cycles, two translate buttons (both directions). Uses HTTPS via translate.googleapis.com. Requires AmiSSL.
gui_weather.js — Weather station
Auto-detects your city from your IP (ip-api.com), then shows current conditions and a 3-day forecast from wttr.in. Font-aware responsive layout.
gui_rss.js — RSS feed reader (v1.0)
A full RSS/Atom reader with a feed list on the left, articles in the middle, reader on the right. Parses RSS and Atom without regex; persists the feed list to S:rss_me.json; supports adding/removing feeds via popup; copies URLs to clipboard. 958 lines — a good "real app" reference.
aminet_browser.js — Aminet client (v1.4)
Browse, search, and download from Aminet. Hardcoded subcategory trees for all 13 top categories. Supports the Recent page, search, readme viewing (in a secondary window with scroller), sort by name/size/date, double-click to download. 1200+ lines — the largest example, shows what a production GadTools app looks like.
Amiga-specific (4 examples)
sysinfo.js — Full system report
Everything os and process expose: runtime version, platform, Kickstart version, CPU model from AttnFlags, memory stats, environment variables. Good "is my setup right" check.
clipboard.js — Clipboard round-trip
Write to clipboard, read back, verify, try a multiline write, clear. Watch the contents update in any Amiga text editor with the clipboard open.
arexx.js — ARexx ports
Lists existing public ports, creates our own NODEAMIGA port, verifies it appears, tries sending to a non-existent port (expected failure), closes the port, verifies it's gone.
ffi.js — Foreign function interface
Reads ExecBase fields with peek16, detects the CPU from AttnFlags, opens/closes libraries, calls exec.AvailMem for chip/fast memory via amiga.call, allocates and pokes memory. A hands-on tour of the FFI.