Skip to content

Repository files navigation

license last-commit repo-top-language repo-language-count

Built with the tools and technologies:

Express npm Mongoose JavaScript EJS Axios


A powerful and customizable API boilerplate built with Node.js, Express, and MongoDB. PixelForge provides a solid foundation for building your own RESTful APIs with features like user authentication, rate limiting, and a dynamic API documentation page.

Live Demo

Contact

Features

  • RESTful API Boilerplate: A solid starting point for your own API.
  • User Authentication: JWT-based authentication for securing your endpoints.
  • Rate Limiting: Protect your API from abuse with flexible rate limiting.
  • Dynamic API Documentation: A beautiful and interactive API documentation page generated automatically from your API files.
  • Customizable Settings: Easily customize your service name, slogan, and other settings through settings.json.
  • Easy to Extend: A simple and intuitive structure for adding new API endpoints.
  • MongoDB Integration: Uses Mongoose for elegant MongoDB object modeling.
  • Ready for Deployment: Includes configuration for easy deployment to Vercel and Render.

Screenshots

Landing Page API Documentation
Landing Page API Documentation
Profile Page Admin Dashboard
Profile Page Admin Dashboard

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

Installation

  1. Clone the repository:

    git clone https://github.com/1dev-hridoy/PixelForge.git
    cd PixelForge
  2. Install dependencies:

    npm install

Configuration

  1. Create a .env file: Create a .env file in the root of the project and add the following environment variables. You can copy the example.env file to get started.

    MONGO_URI=your_mongodb_connection_string
    JWT_SECRET=your_jwt_secret
    SESSION_SECRET=your_session_secret
    ADMIN_EMAIL=your_admin_email@example.com
  2. Get your MongoDB Connection String:

    • Go to MongoDB Atlas and create a new project and a new cluster.
    • In your cluster, go to "Database Access" and create a new database user with a username and password.
    • Go to "Network Access" and add your current IP address to the IP access list.
    • Go to "Databases", click "Connect" on your cluster, select "Connect your application", and copy the connection string.
    • Replace <username>, <password>, and <dbname> in the connection string with your database user's credentials and your database name.
  3. Customize settings.json: Open the settings.json file and customize the service name, slogan, and other settings to your liking.

    {
      "service": {
        "name": "PixelForge",
        "slogan": "A powerful and customizable API boilerplate.",
        "ownerName": "1dev-hridoy",
        "serverURI": "http://localhost:3000",
        "headDoc": "Welcome to the PixelForge API Documentation"
      },
      "buttons": [
        {
          "name": "GitHub",
          "url": "https://github.com/1dev-hridoy/PixelForge"
        }
      ],
      "rateLimit": {
        "free": {
          "requestsPerMinute": 10,
          "requestsPerDay": 100
        },
        "premium": {
          "requestsPerMinute": 60,
          "requestsPerDay": 1000
        }
      },
      "apiPrefix": "PF_"
    }

Usage

To run the application in development mode, use the following command:

node .

The server will start on http://localhost:3000 by default.

Deployment

Deploying to Vercel

  1. Create a vercel.json file in the root of your project with the following content:
    {
      "version": 2,
      "builds": [
        {
          "src": "server.js",
          "use": "@vercel/node",
          "config": {
            "includeFiles": ["settings.json"]
          }
        }
      ],
      "routes": [
        {
          "src": "/(.*)",
          "dest": "server.js"
        }
      ],
      "crons": [
        {
          "path": "/api/cron/reset-daily-limits",
          "schedule": "0 0 * * *"
        }
      ]
    }
  2. Push your code to your GitHub repository.
  3. Go to Vercel and create a new project, importing your GitHub repository.
  4. Vercel will automatically detect that it's a Node.js project.
  5. Add your environment variables from your .env file to the Vercel project settings.
  6. Deploy!

Deploying to Render

  1. Push your code to your GitHub repository.
  2. Go to Render and create a new "Web Service".
  3. Connect your GitHub repository.
  4. Render will automatically detect that it's a Node.js project.
  5. Set the "Start Command" to node ..
  6. Add your environment variables from your .env file in the "Environment" section.
  7. Deploy!

Creating New APIs

To create a new API endpoint, follow these steps:

  1. Create a new JavaScript file in the api directory. You can organize your APIs into subdirectories by category. For example, to create a new "fun" API, you could create a file at api/fun/my-new-api.js.

  2. Define the API metadata and handler in the new file. The file must export a meta object and a handler function.

    // api/fun/my-new-api.js
    
    const meta = {
        name: "My New API",
        version: "1.0.0",
        description: "A new API that does something fun.",
        author: "Your Name",
        method: "get", // or "post", "put", "delete"
        category: "fun",
        path: "/my-new-api",
        params: {
            param1: "required",
            param2: "optional"
        }
    };
    
    const handler = async (req, res, meta) => {
        try {
            const { param1, param2 } = req.query;
    
            if (!param1) {
                return res.status(400).json({
                    error: "param1 is required"
                });
            }
    
            // Your API logic here
    
            res.json({
                message: "Hello from my new API!",
                param1,
                param2
            });
    
        } catch (error) {
            res.status(500).json({
                error: error.message
            });
        }
    };
    
    module.exports = { meta, handler };
  3. The server will automatically register the new endpoint when you restart it. The endpoint will be available at /api/fun/my-new-api and will appear on the API documentation page.

Contributing

Contributions are welcome! Please feel free to submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A powerful and customizable API boilerplate built with Node.js, Express, and MongoDB.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages