-
Notifications
You must be signed in to change notification settings - Fork 0
Home
NotNexx edited this page Feb 24, 2025
·
3 revisions
Welcome to the Simple API Router Wiki! This documentation provides an in-depth guide to installing, using, and extending the package.
Ensure you have Node.js and npm installed:
node -v
npm -v
To install the package, run:
npm install @notnexx/n-sar
Create an Express server and use n-sar
to load routes from the api/
folder:
const express = require('express');
const loadRoutes = require('@notnexx/n-sar');
const app = express();
const PORT = 3000;
app.use(express.json());
loadRoutes(app);
app.listen(PORT, () => {
console.log(`Server running at http://localhost:${PORT}`);
});
To create a sample project with predefined structure:
npx n-sar my-api-project
This creates a folder with:
my-api-project/
βββ api/
β βββ router.js
β βββ user.js
βββ package.json
βββ server.js
Start the project:
cd my-api-project
npm install
node server.js
Each file in api/
represents an endpoint. Example:
const express = require('express');
const router = express.Router();
router.get('/', (req, res) => {
res.json({ message: 'User endpoint' });
});
module.exports = router;
This automatically registers the route:
GET /user
To generate a frontend API client that connects to your backend:
npx n-sar export-routes http://localhost:3000
This creates apiClient.js
:
import APIClient from './apiClient';
APIClient.user().then(response => console.log(response));
- Fork the repository.
- Create a new branch (
git checkout -b feature-xyz
). - Commit changes (
git commit -m 'Added feature xyz'
). - Push (
git push origin feature-xyz
). - Create a Pull Request.
This project is licensed under the MIT License.