Triva is a class-based Node.js HTTP and HTTPS framework. You create an app with new build(...), register routes on that instance, and start the server with app.listen(...).
npm install trivaTriva targets modern Node.js. Use Node 18 or newer so the runtime and extension packages behave consistently.
import { build } from 'triva';
const app = new build({ env: 'development' });
app.get('/api/users', (req, res) => {
res.json([
{ id: 1, name: 'Ada' },
{ id: 2, name: 'Grace' }
]);
});
app.get('/api/users/:id', (req, res) => {
const users = [
{ id: 1, name: 'Ada' },
{ id: 2, name: 'Grace' }
];
const user = users.find((entry) => entry.id === Number(req.params.id));
if (!user) {
return res.status(404).json({ error: 'User not found' });
}
res.json(user);
});
app.listen(3000);- Route methods on the app instance:
app.get(),app.post(),app.put(),app.del(),app.patch(),app.all(), andapp.route() - Request parsing through
await req.json()andawait req.text() - Response helpers such as
res.status(),res.json(),res.send(),res.html(),res.redirect(), andres.sendFile() - Configurable cache adapters through
cacheplus the exportedcachesingleton for runtime reads and writes - Built-in throttle, retention, and error-tracking support through constructor options
- HTTP or HTTPS startup through
protocolandssl