Built with the tools and technologies:
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.
- 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.
| Landing Page | API Documentation |
|---|---|
| Profile Page | Admin Dashboard |
|---|---|
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
- Node.js (v14 or later)
- npm
- Git
- A MongoDB database. You can create a free one on MongoDB Atlas.
-
Clone the repository:
git clone https://github.com/1dev-hridoy/PixelForge.git cd PixelForge -
Install dependencies:
npm install
-
Create a
.envfile: Create a.envfile in the root of the project and add the following environment variables. You can copy theexample.envfile 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
-
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.
-
Customize
settings.json: Open thesettings.jsonfile 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_" }
To run the application in development mode, use the following command:
node .The server will start on http://localhost:3000 by default.
- Create a
vercel.jsonfile 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 * * *" } ] } - Push your code to your GitHub repository.
- Go to Vercel and create a new project, importing your GitHub repository.
- Vercel will automatically detect that it's a Node.js project.
- Add your environment variables from your
.envfile to the Vercel project settings. - Deploy!
- Push your code to your GitHub repository.
- Go to Render and create a new "Web Service".
- Connect your GitHub repository.
- Render will automatically detect that it's a Node.js project.
- Set the "Start Command" to
node .. - Add your environment variables from your
.envfile in the "Environment" section. - Deploy!
To create a new API endpoint, follow these steps:
-
Create a new JavaScript file in the
apidirectory. You can organize your APIs into subdirectories by category. For example, to create a new "fun" API, you could create a file atapi/fun/my-new-api.js. -
Define the API metadata and handler in the new file. The file must export a
metaobject and ahandlerfunction.// 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 };
-
The server will automatically register the new endpoint when you restart it. The endpoint will be available at
/api/fun/my-new-apiand will appear on the API documentation page.
Contributions are welcome! Please feel free to submit a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.