-
Notifications
You must be signed in to change notification settings - Fork 0
Home
NotNexx edited this page Feb 24, 2025
·
3 revisions
This documentation provides a comprehensive guide to installing, using, and extending the package efficiently.
Before installing, ensure you have Node.js and npm installed:
node -v
npm -v
To install the package, run the following command:
npm install @notnexx/n-sar
To quickly set up 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 a predefined structure:
npx n-sar my-api-project
This creates a folder structure like:
my-api-project/
βββ api/
β βββ router.js
β βββ user.js
βββ package.json
βββ server.js
Start the project by running:
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 your changes:
git commit -m 'Added feature xyz'
-
Push to GitHub:
git push origin feature-xyz
- Create a Pull Request and describe your changes.
This project is licensed under the MIT License.