Servers
server.jsread-only
const express = require("express");
const app = express();
app.use(express.json());
const users = [
{
id: 1,
name: "Alice Johnson",
email: "alice@example.com",
role: "admin"
},
{
id: 2,
name: "Bob Smith",
email: "bob@example.com",
role: "user"
},
{
id: 3,
name: "Charlie Brown",
email: "charlie@example.com",
role: "user"
}
];
app.get("/", (req, res) => {
res.json({
name: "Express API",
version: "1.0.0",
endpoints: [
"/api/users",
"/api/time",
"/api/random"
]
});
});
app.get("/api/users", (req, res) => {
console.log("GET /api/users");
res.json(users);
});
app.get("/api/users/:id", (req, res) => {
console.log("GET /api/users/" + req.params.id);
const user = users.find((u) => u.id === Number(req.params.id));
if (user) res.json(user);
else res.status(404).json({ error: "User not found" });
});
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,
uuid: "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
const r = Math.random() * 16 | 0;
return (c === "x" ? r : r & 3 | 8).toString(16);
})
});
});
const server = app.listen(3e3, () => {
console.log("Express server running on port 3000");
});
globalThis.__server = server;
module.exports = app;
An Express.js REST API server running client-side. It boots, installs dependencies, and runs a full Express application with multiple endpoints, middleware, and an interactive API explorer for testing routes.
How it works
- GET routes serve users, time, and random data
- The Express middleware chain handles requests through multiple layers
- An interactive API explorer lets you test endpoints and see responses live
- A status indicator tracks the server lifecycle: idle, installing, running, or error
Try it yourself
- Click on any route in the API explorer to send a request
- Watch the terminal for server logs and responses
- Observe the server status indicator in the header