Lightweight API manager for Node.js: automatically loads routes from a folder, enables per-route configuration, and provides built-in logging and log cleanup.
- Dynamic Route Loading: Automatically loads JavaScript files from the
routes/directory. - Config Management: Enable or disable routes easily via the JSONC config file.
- CORS Support: Customize allowed origins and HTTP methods.
- Logging System: Supports
info,warn, anderrorlevels, with automatic log directory creation. - Log Cleanup: Clear logs on start using config or CLI flag
--clear-logs. - Graceful Shutdown: Type
stopin the terminal or useCtrl+C/killto cleanly exit and optionally clear logs.
Clone the repository and install dependencies:
git clone https://github.com/IdiotStudiosCo/Route-Master.git
cd route-master
npm installnpm startnpm start -- --clear-logsOr via the npm script:
npm run clear-logsEdit the config.jsonc file to customize your API:
info.port– Port your server will run on.info.getmsg– Message returned when accessing/.routes– Enable or disable route files. Routes not listed will be added automatically.cors– Configure allowed origins and HTTP methods.logging– Control log level, log directory, enable/disable logging, or clear logs on next start.
Place your route files in the routes/ folder. Example:
// routes/example.js
import express from 'express';
const router = express.Router();
router.get('/', (req, res) => {
res.send({ message: "Example route works!" });
});
export default router;- Each route must export a default
router. - The loader mounts routes based on the file name:
/example→example.js.
-
Logs are stored in the directory specified in
config.jsonc(logging.dir). -
Logging levels:
info– logs all messages.warn– logs warnings and errors.error– logs only errors.
Pull requests are welcome!
- Follow the existing route structure.
- Keep logging conventions consistent.
- Ensure new routes are tested before submitting.
{ "info": { // The port the server will run on "port": 3000, // The Message that will be returned when the API is accessed at / "getmsg": "IdiotStudios API" // Should change this }, // The Routes that will be enabled // If a route is not listed here, it will be made automatically "routes": { "config": true, "crafty": true, "message": true, "suggest": true }, "cors": { "origin": "*", "methods": [ "GET", "POST" ] }, "logging": { // The level in which logs will be written // Options: "info", "warn", "error" // "info" will log all messages // "warn" will log warnings and errors // "error" will only log errors "level": "info", // The Directory where logs will be stored // If the directory does not exist, it will be created automatically "dir": "logs/", // Weather Logging is enabled // If false, no logs will be written "enabled": true, // Will clear logs on next server start // Note it will also stop the process after clearing "clearOnNextStart": false } }