A lightweight and serverless CDN utilizing MEGA for file storage and delivery.
- File upload and delivery via MEGA storage
- Multiple account support (load balancing)
- Multiple Files and folder Upload Support
- Cool and Professional UI
- Optional upload-protection using
Authorization
Header - Optional auto-deletion with configurable time periods
- Supports both
MongoDB
andJson
- Serverless deployment ready
git clone https://github.com/IRON-M4N/MegaCDN.git
cd MegaCDN
npm install
- If You Don't Have a Heroku Account, Create An Account.
- Now Deploy To Heroku.
- Create Vercel Account If You Don't Have.
- Deploy on Vercel.
- If You Don't Have Railway Account, Create First.
- Now Deploy The Repo.
- Create Render Account If You Don't Have Any.
- Deploy Now.
- Create Account If You Don't Have.
- Now Deploy.
Modify config.js
or use environment variables. Example .env
file:
PORT=3000 # Port to run the app
MEGA_ACCOUNT=email:pass;email:pass # Multiple accounts for load balancing
TEMP=memory # Upload storage option
AUTO_DELETE=true # Enable/disable auto-deletion
DELETE_TIME=1440 # Minutes until deletion (default: 1 day)
MONGODB_URI=null # Optional MongoDB connection string
AUTHORIZATION=true # Enable/disable secure uploading
AUTH_TOKEN=YOUR_BEARER_TOKEN # Bearer token for authentication
MAX_FILES=10 # Maximum files per upload
MAX_FILE_SIZE=50 # Maximum file size in MB
CACHE_TTL=3600 # Cache duration in seconds
MAX_REQUESTS=100 # Max upload requests in specific time
RATE_LIMIT=1 minute # 100 req per minute
Note: If you change AUTH_TOKEN
then update it in public/script.js at line 189
Using PM2 for process management:
npm start
To stop or restart:
npm stop
npm restart
Send a POST request to /upload with a multipart form containing a file.
Curl - Single Mode
# Single file without Authorization
curl -X POST -F "[email protected]" -F "mode=single" http://yourdomain.com/upload
# Multiple Files With Authorizatoin
curl -X POST -H "Authorization: Bearer YOUR_BEARER_TOKEN" -F "[email protected]" -F "[email protected]" -F "mode=single" http://yourdomain.com/upload
Curl - Dual Mode
# Single file without Authorization
curl -X POST -F "[email protected]" -F "mode=dual" -F "[email protected]" http://yourdomain.com/upload
# Multiple Files With Authorizatoin
curl -X POST -H "Authorization: Bearer YOUR_BEARER_TOKEN" -F "[email protected]" -F "[email protected]" -F "[email protected]" -F "mode=dual" -F "[email protected]" http://yourdomain.com/upload
Node.js - Single Mode
// Single file without Authorization
const fs = require("fs");
const axios = require("axios");
const FormData = require("form-data");
async function uploadSingle() {
const form = new FormData();
form.append("file", fs.createReadStream("image.jpg"));
form.append("mode", "single");
const res = await axios.post("http://yourdomain.com/upload", form, {
headers: form.getHeaders(),
});
console.log(res.data);
}
uploadSingle();
// Multiple Files with Authorization
async function uploadMultiple() {
const form = new FormData();
form.append("file", fs.createReadStream("image1.jpg"));
form.append("file", fs.createReadStream("image2.png"));
form.append("mode", "single");
const headers = {
...form.getHeaders(),
Authorization: "Bearer YOUR_BEARER_TOKEN",
};
try {
const res = await axios.post("http://yourdomain.com/upload", form, { headers });
console.log("Upload successful:", res.data);
} catch (error) {
console.error("Upload failed:", error.response?.data || error.message);
}
}
uploadMultiple();
Node.js - Dual Mode
// Single file without Authorization
const fs = require("fs");
const axios = require("axios");
const FormData = require("form-data");
async function uploadDual() {
const form = new FormData();
form.append("file", fs.createReadStream("image.jpg"));
form.append("mode", "dual");
form.append("email", "[email protected]");
const res = await axios.post("http://yourdomain.com/upload", form, {
headers: form.getHeaders(),
});
console.log(res.data);
}
uploadDual();
// Multiple Files with Authorization
async function uploadMultiple() {
const form = new FormData();
form.append("file", fs.createReadStream("image1.jpg"));
form.append("file", fs.createReadStream("image2.png"));
form.append("mode", "dual");
form.append("email", "[email protected]");
const headers = {
...form.getHeaders(),
Authorization: "Bearer YOUR_BEARER_TOKEN",
};
try {
const res = await axios.post("http://yourdomain.com/upload", form, { headers });
console.log("Upload successful:", res.data);
} catch (error) {
console.error("Upload failed:", error.response?.data || error.message);
}
}
uploadMultiple();
Parameter | Description |
---|---|
file |
The file to upload. |
mode |
Upload mode: single (default) or dual (requires email ). |
email |
(Optional) Required if mode=dual , specifies which account to use. |
{
"success": true,
"files": [
{
"url": "https://your_domain.com/media/your_file",
"name": "your_file.png",
"size": 51470,
"formattedSize": "50.26 KB",
"expires": "86400 sec",
"formattedExpires": "1 day"
}
]
}
- Add custom file name
- Proper logging (error and alerts)
- Fork the repository
- Create a new branch (
feature-web
) - Commit your changes
- Open a pull request
© IRON-M4N