thaitype/data-viewer

Provide express middleware as external library

Closed this issue · 0 comments

import { DataViewer } from '@thaitype/data-viewer-server';

const getUsers = async () => (await fetch('https://jsonplaceholder.typicode.com/users')).json();
const getPosts = async () => (await fetch('https://jsonplaceholder.typicode.com/posts')).json();

const dataViewer = new DataViewer();

dataViewer.addHeader('User Table');
dataViewer.addTable((await getUsers()));
dataViewer.addHeader('Post Table');
dataViewer.addTable(await getPosts());

const app = express();
dataViewer.registerMiddleware(app);
app.listen(3000, async () => console.log(`Already servered on http://localhost:3000/viewer`));