1.0.4 • Published 4 months ago

backend-generator v1.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

Backend Generator

This is a Node.js Express & MongoDB backend generator that creates a fully functional API based on a given JSON schema. It automates model, controller, and route generation.

SAMPLE SCHEMA:

{ "User": { "fields": { "name": { "type": "String", "required": true, "searchable": true }, "email": { "type": "String", "required": true, "unique": true, "filterable": true }, "password": { "type": "String", "required": true }, "role": { "type": "String", "enum": "admin", "user", "default": "user", "filterable": true }, "createdAt": { "type": "Date", "default": "Date.now", "sortable": true } } }, "Product": { "fields": { "name": { "type": "String", "required": true, "searchable": true }, "description": { "type": "String", "searchable": true }, "price": { "type": "Number", "required": true, "sortable": true, "filterable": true }, "category": { "type": "String", "filterable": true }, "stock": { "type": "Number", "default": 0, "sortable": true }, "createdAt": { "type": "Date", "default": "Date.now", "sortable": true } } }, "Order": { "fields": { "userId": { "type": "mongoose.Schema.Types.ObjectId", "ref": "User", "required": true }, "products": { "type": "Array", "required": true, "items": { "productId": { "type": "mongoose.Schema.Types.ObjectId", "ref": "Product" }, "quantity": { "type": "Number", "required": true } } }, "totalAmount": { "type": "Number", "required": true, "sortable": true }, "status": { "type": "String", "enum": "pending", "shipped", "delivered", "cancelled", "default": "pending", "filterable": true }, "createdAt": { "type": "Date", "default": "Date.now", "sortable": true } } }, "Category": { "fields": { "title": { "type": "String", "required": true }, "description": { "type": "String" } } } }

šŸ“Œ Features

Automatic CRUD API generation

Express.js for routing

Mongoose for MongoDB integration

Environment variable support with .env

Dynamic route loading

šŸš€ Getting Started

1ļøāƒ£ Generate the Backend

Run the following command to generate your backend project:

node backend-generator myProject schema.json

myProject: The name of your new project folder.

schema.json: The path to the schema defining your models.

2ļøāƒ£ Navigate to the Project

cd myProject

3ļøāƒ£ Install Dependencies

npm install

4ļøāƒ£ Start the Server

For production:

npm start

For development (auto-restarts on changes):

npm run dev

šŸ“‚ Project Structure

myProject/ │-- models/ # Mongoose models │-- controllers/ # API logic │-- routes/ # Express routes │-- server.js # Entry point │-- .env # Environment variables │-- package.json # Project config

šŸ“Œ API Endpoints

Each model in your schema will have these endpoints automatically:

Create: POST /model

Get All: GET /model

Get by ID: GET /model/:id

Update: PUT /model/:id

Delete: DELETE /model/:id

šŸ›  Configuration

Set your database connection string in .env:

MONGO_URI=mongodb://localhost:27017/myDatabase

šŸ“œ License

This project is open-source. Feel free to modify and use it as needed!

Happy Coding! šŸš€

1.0.2

4 months ago

1.0.1

4 months ago

1.0.4

4 months ago

1.0.3

4 months ago

1.2.0

3 years ago

1.3.5

3 years ago

1.6.0

3 years ago

1.1.5

3 years ago

1.5.0

3 years ago

1.3.0

3 years ago

1.1.46

3 years ago

1.1.45

3 years ago

1.1.42

3 years ago

1.1.41

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago