json-express-crud
v2.0.2
Published
This project is a simple REST API based on Express.js, allowing you to manage collections of data stored in JSON files. It handles authentication, authorization, file uploads, and data persistence.
Downloads
22
Readme
Express JSON Server
This project is a simple REST API based on Express.js, allowing you to manage collections of data stored in JSON files. It handles authentication, authorization, file uploads, and data persistence.
Features
- CRUD operations on collections (Create, Read, Update, Delete)
- Authentication and authorization via token
- Ownership assignment for each resource
- File upload (images) associated with a resource using Multer
- Automatic persistence in JSON files (
data/db.json,data/auth.json)
Usage
Create a folder:
npx json-express-crud
Main Endpoints
POST /<collection>: Create a resourceGET /<collection>: List all resourcesGET /<collection>/<id>: Read a resourcePUT /<collection>/<id>: Update a resourceDELETE /<collection>/<id>: Delete a resourcePOST /<collection>/<id>/upload: Upload an image for a resource (fieldfilein amultipart/form-dataform)
Authentication
POST /auth/login: Authenticate withemailandpassword- Returns a JWT token to use in the
Authorizationheader
- Returns a JWT token to use in the
POST /auth/register: Register a new user withemail,password, androle(optional, default isuser) Note: more user information can be added during registration
Customization
- Edit
data/db.jsonto add or modify collections - Edit
data/auth.jsonto manage users and roles
Breaking changes
v2.0.0
- Normalized API response structure: All non-error responses now return an object with a
dataproperty containing the actual response data.- updated
GET /<collection>to return{ count: 999, data: [...] }
- updated
Main Dependencies
- express
- multer
License
MIT
