Skip to content

Installation

NotNexx edited this page Feb 24, 2025 · 1 revision

πŸ“₯ Installation & Setup

Follow these steps to install and set up Simple API Router in your project.

πŸ“Œ Prerequisites

Before installing, make sure you have:

  • Node.js (latest LTS version recommended)
  • npm (comes with Node.js) or yarn

πŸš€ Installation

To install Simple API Router, run:

Using npm:

npm install @notnexx/n-sar

Using yarn:

yarn add @notnexx/n-sar

πŸ› οΈ Setup

1. Manual Setup in an Existing Project

If you already have an Express project, you can use @notnexx/n-sar to automatically load all routes from the api/ directory.

Example:

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}`);
});

2. Create a New API Project

To quickly generate a new API project with a predefined structure, use:

npx n-sar create my-api-project

This creates a new project folder my-api-project with the following structure:

my-api-project/
β”œβ”€β”€ api/
β”‚   β”œβ”€β”€ router.js
β”‚   └── user.js
β”œβ”€β”€ package.json
└── server.js

Then, install dependencies and start the server:

cd my-api-project
npm install
node server.js

Your API server will now run at http://localhost:3000.

πŸ”Ž Verify Installation

To check if Simple API Router is installed correctly, run:

npm list @notnexx/n-sar

or

yarn list @notnexx/n-sar

If the package appears in the list, the installation was successful.

πŸ“– Next Steps


πŸ’‘ Need help? Feel free to [open an issue](../issues) or start a [discussion](../discussions).