mnglab
Version:
Dead simple REST micro-framework with modular routing, API key, rate limiting, full HTTP response handling, dev tools, JSON DB, file helpers, endpoint stats, and professional developer experience.
19 lines (9 loc) • 929 B
JavaScript
// tools/create.js const fs = require('fs'); const path = require('path'); const chalk = require('chalk');
const name = process.argv[2]; if (!name) { console.log(chalk.red('❌ Please provide a route name.')); process.exit(1); }
const routesDir = path.join(process.cwd(), 'routes'); if (!fs.existsSync(routesDir)) fs.mkdirSync(routesDir);
const filePath = path.join(routesDir, ${name}.js); if (fs.existsSync(filePath)) { console.log(chalk.yellow('⚠️ Route already exists!')); process.exit(1); }
const template = ` // routes/${name}.js const { route } = require('../index');
route.get('/${name}', (req, res) => { res.json({ success: true, message: 'GET /${name} OK' }); });
route.post('/${name}', { body: ['field1'] }, (req, res) => { res.json({ success: true, data: req.body }); });
module.exports = true; `;
fs.writeFileSync(filePath, template); console.log(chalk.green(✅ Route created at routes/${name}.js));