← demos
/
almostnode
/
Express Server
express · npm install
server.js
Run Server
const express = require('express'); const app = express(); // Middleware to parse JSON app.use(express.json()); // Home route app.get('/', (req, res) => { console.log('GET /'); res.send(` <!DOCTYPE html> <html> <head> <style> body { font-family: system-ui, sans-serif; padding: 2rem; background: #0c0c0c; min-height: 100vh; margin: 0; display: flex; align-items: center; justify-content: center; color: #c0c0c0; } .card { border: 1px solid #2a2a2a; padding: 2rem; max-width: 480px; } h1 { color: #00ff88; margin-top: 0; } a { color: #00ff88; font-weight: bold; } code { background: #1a1a1a; padding: 2px 6px; border: 1px solid #2a2a2a; } </style> </head> <body> <div class="card"> <h1>Express Agent Runtime</h1> <p>This Express server is running inside an isolated browser runtime.</p> <p>Routes:</p> <p><a href="/api/users">/api/users</a> — list all users</p> <p><a href="/api/time">/api/time</a> — current time</p> </div> </body> </html> `); }); // API routes app.get('/api/users', (req, res) => { console.log('GET /api/users'); res.json([ { id: 1, name: 'Alice', email: 'alice@example.com' }, { id: 2, name: 'Bob', email: 'bob@example.com' }, { id: 3, name: 'Charlie', email: 'charlie@example.com' } ]); }); app.get('/api/time', (req, res) => { console.log('GET /api/time'); res.json({ timestamp: Date.now(), iso: new Date().toISOString(), readable: new Date().toLocaleString() }); }); app.get('/api/random', (req, res) => { console.log('GET /api/random'); res.json({ number: Math.random(), dice: Math.floor(Math.random() * 6) + 1 }); }); // 404 handler app.use((req, res) => { res.status(404).json({ error: 'Not Found', path: req.path }); }); // Start server app.listen(3000, () => { console.log('Express server running on port 3000'); });
Preview
Ready
Console