create an api with express in javascript

index.tsx
const express = require('express');
const app = express();
const port = 3000;

app.get('/api/users', (req, res) => {
    res.json({ users: [
        { name: 'Alice', age: 30 },
        { name: 'Bob', age: 35 }
    ]});
});

app.listen(port, () => {
    console.log(`API server is running at http://localhost:${port}`);
});
323 chars
15 lines

related categories

gistlibby LogSnag