Create a minimal working Replit example.
Use when starting a new Replit integration, testing your setup,
or learning basic Replit API patterns.
Trigger with phrases like "replit hello world", "replit example",
"replit quick start", "simple replit code".
Build a working Replit app that demonstrates core platform services: Express/Flask server, Replit Database (key-value store), Object Storage (file uploads), Auth (user login), and PostgreSQL. Produces a running app you can deploy.
Prerequisites
Replit App created (template or blank)
.replit and replit.nix configured (see replit-install-auth)
Node.js 18+ or Python 3.10+
Instructions
Step 1: Node.js — Express + Replit Database
// index.ts
import express from 'express';
import Database from '@replit/database';
const app = express();
const db = new Database();
app.use(express.json());
// Health check with Replit env vars
app.get('/health', (req, res) => {
res.json({
status: 'ok',
repl: process.env.REPL_SLUG,
owner: process.env.REPL_OWNER,
timestamp: new Date().toISOString(),
});
});
// Replit Key-Value Database CRUD
// Limits: 50 MiB total, 5,000 keys, 1 KB per key, 5 MiB per value
app.post('/api/items', async (req, res) => {
const { key, value } = req.body;
await db.set(key, value);
res.json({ stored: key });
});
app.get('/api/items/:key', async (req, res) => {
const value = await db.get(req.params.key);
if (value === null) return res.status(404).json({ error: 'Not found' });
res.json({ key: req.params.key, value });
});
app.get('/api/items', async (req, res) => {
const prefix = (req.query.prefix as string) || '';
const keys = await db.list(prefix);
res.json({ keys });
});
app.delete('/api/items/:key', async (req, res) => {
await db.delete(req.params.key);
res.json({ deleted: req.params.key });
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
console.log(`Repl: ${process.env.REPL_SLUG} by ${process.env.REPL_OWNER}`);
});