const express = require('express'); const router = express.Router(); const { exec } = require('child_process'); let dir = process.argv[2] || '.'; router.get('/', (req, res) => { res.send('Welcome to our minimalist web application!') }); router.get('/api/posts', (req, res) => { let page = req.query.page || 1; let limit = req.query.limit || 10; exec(`./routes/listPosts ${dir} ${page} ${limit}`, (error, stdout, stderr) => { if (error) { console.log(`error: ${error.message}`); return; } if (stderr) { console.log(`stderr: ${stderr}`); return; } let posts = stdout.split('\n').filter(Boolean); res.json(posts); }); }); router.get('/posts', (req, res) => { let page = req.query.page || 1; let limit = req.query.limit || 10; exec(`./routes/listPosts ${dir} ${page} ${limit}`, (error, stdout, stderr) => { if (error) { console.log(`error: ${error.message}`); return; } if (stderr) { console.log(`stderr: ${stderr}`); return; } let posts = stdout.split('\n').filter(Boolean); let html = '