Servers

WebSocket chat

A chat room on Express and ws: the page talks to the server over a real WebSocket, and bash posts into the same room.

bash · ~/app
editor

The project's files open here.

Changes save as you type. Press Escape, then Tab, to leave the editor.

preview

The page the server serves shows here.

  1. boot
  2. npm install
  3. start
  4. ready

idle

betaClientVM is pre-1.0 (v0.2.0): things can break, and APIs may change between releases. Found a bug? Open an issue.

About this demo

The server is the unmodified ws package on an Express app. When the page opens a WebSocket to its own origin, the preview’s service worker hands it to the server listening inside the instance; nothing leaves the tab.

Send a message in the page, or post one from bash with curl: every connected page gets it, and the server logs it in the terminal.

How it's built

const app = await vm.createInstance({ fs: { from: { home: { user: { app: chat } } } } });

app.onPortOpen((port, url) => (preview.src = url));
// the page's WebSocket reaches the ws server through the preview's service worker
await app.exec('npm install && npm start', { cwd: '/home/user/app' });