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.
43 lines (35 loc) • 1.13 kB
JavaScript
const fs = require('fs');
const path = require('path');
const chalk = require('chalk');
function ensureDir(dirPath) {
const fullPath = path.resolve(process.cwd(), dirPath);
if (!fs.existsSync(fullPath)) {
fs.mkdirSync(fullPath, { recursive: true });
console.log(chalk.green(`[MngLab] Created directory: ${dirPath}`));
}
}
function ensureFile(filePath, content = '') {
const fullPath = path.resolve(process.cwd(), filePath);
if (!fs.existsSync(fullPath)) {
fs.writeFileSync(fullPath, content);
console.log(chalk.green(`[MngLab] Created file: ${filePath}`));
}
}
function createExampleRoute() {
const example = `
const { route } = require('../index');
route.get('/hello', (req, res) => {
res.json({ success: true, message: 'Hello from MngLab!' });
});
`.trim();
ensureDir('routes');
ensureFile('routes/hello.js', example);
}
function setupProject() {
ensureDir('routes');
ensureFile('db.json', JSON.stringify({}, null, 2));
createExampleRoute();
console.log(chalk.blueBright('\n✅ Project initialized! Run with:'));
console.log(chalk.yellow('node index.js'));
}
setupProject();