Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/elmarti/justjson
https://github.com/elmarti/justjson
Last synced: 5 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/elmarti/justjson
- Owner: elmarti
- Created: 2023-06-01T09:54:42.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-06-06T11:43:38.000Z (over 1 year ago)
- Last Synced: 2024-11-02T20:42:13.680Z (about 2 months ago)
- Language: JavaScript
- Size: 54.4 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Express JS Dynamic Routes
This project demonstrates a simple Express.js server with the capability to dynamically load routes based on a specified directory.
## Getting Started
To get started, you need to have Node.js and npm installed on your system.
## Installation
1. Clone the repository: `git clone https://github.com/yourusername/yourrepository.git`
2. Navigate into the directory: `cd yourrepository`
3. Install dependencies: `npm install`## Usage
1. The server loads routes based on the folders in the specified directory (defaulting to 'routes').
2. For each route, you need a `data.json` file and an optional `config.json` file in the corresponding directory.
3. The `data.json` file contains the initial data for the route.
4. The `config.json` file can specify which HTTP methods (get, post, patch, delete) are enabled for the route and what field should be used as the id for PATCH and DELETE requests. If no config file is present, it defaults to enabling all methods and using 'id' as the id field.Example structure of `data.json`:
```json
[
{
"id": "1",
"name": "John Doe",
"email": "[email protected]"
},
{
"id": "2",
"name": "Jane Doe",
"email": "[email protected]"
}
]
```Example structure of config.json:
```json
{
"methods": ["get", "post", "patch", "delete"],
"idField": "id"
}
```
Run the server: `npm start` or `yarn start`The server will print out the registered routes on startup. You can access the routes on http://localhost:1234/{route}