@koding88/wakeup-render
v1.0.0
Published
A package to keep Render servers awake by mutual pinging
Downloads
70
Maintainers
Readme
Wakeup Render
A lightweight Node.js package that keeps your Render.com servers awake by implementing mutual pinging between servers. Perfect for preventing your free-tier Render servers from going to sleep after 15 minutes of inactivity.
Features
- 🔄 Automatic mutual pinging between servers
- 📊 Built-in health check and metrics endpoints
- 🔒 HTTPS support with production-grade security
- 📝 Detailed logging with Winston
- ⚡ Smart retry mechanism with configurable parameters
- 🛡️ Security headers out of the box
- 🚀 Easy integration with existing Express apps
Installation
npm install @koding88/wakeup-render
# or
yarn add @koding88/wakeup-render
Quick Start
- Create a
.env
file:
PORT=3000
PING_URL=https://your-other-server.onrender.com
NODE_ENV=production
- Create a simple server:
require('dotenv').config();
const { createWakeUpServer } = require('@koding88/wakeup-render');
const config = {
port: process.env.PORT || 3000,
pingUrl: process.env.PING_URL,
interval: 30000 // 30 seconds
};
createWakeUpServer(config);
Integration with Existing Express App
If you already have an Express application, you can run the wake-up server alongside it:
require('dotenv').config();
const express = require('express');
const { createWakeUpServer } = require('@koding88/wakeup-render');
// Your main Express app
const app = express();
app.get('/api/your-route', (req, res) => {
res.json({ message: 'Hello from main app' });
});
// Start your main app
app.listen(4000, () => {
console.log('Main application running on port 4000');
});
// Start wake-up server on a different port
const wakeupConfig = {
port: process.env.WAKEUP_PORT || 3000,
pingUrl: process.env.PING_URL,
interval: 30000
};
createWakeUpServer(wakeupConfig);
Configuration Options
| Option | Type | Default | Description | |--------|------|---------|-------------| | port | number | 3000 | Port number for the wake-up server | | pingUrl | string | required | URL of the server to ping | | interval | number | 30000 | Ping interval in milliseconds | | retryDelay | number | 5000 | Delay between retry attempts | | maxRetries | number | 3 | Maximum number of retry attempts |
API Endpoints
Health Check
GET /
Response:
{
"status": "alive",
"lastPing": "2024-01-20T10:00:00.000Z",
"uptime": 3600
}
Metrics
GET /metrics
Response:
{
"status": "running",
"lastPingTime": "2024-01-20T10:00:00.000Z",
"failedAttempts": 0,
"pingUrl": "https://your-other-server.onrender.com",
"interval": 30000,
"uptime": 3600,
"memory": {
"heapUsed": 13721600,
"heapTotal": 29876224,
"external": 1841478
}
}
Deployment on Render.com
Create two servers on Render.com
For Server 1, set environment variables:
PORT=3000
PING_URL=https://server2.onrender.com
NODE_ENV=production
- For Server 2, set environment variables:
PORT=3000
PING_URL=https://server1.onrender.com
NODE_ENV=production
- Deploy both servers
- The servers will automatically start pinging each other
- Each server will stay awake due to the mutual pinging
- Monitor the status through the /metrics endpoint
Security Features
- HTTPS support with proper certificate validation in production
- Security headers:
- X-Content-Type-Options: nosniff
- X-Frame-Options: DENY
- X-XSS-Protection: 1; mode=block
- Response time tracking
- Error handling with environment-aware responses
Logging
The package uses Winston for logging with the following outputs:
- Console: Colored logs for development
- error.log: Error-level logs
- combined.log: All logs
Best Practices
- Use different ports for your main app and wake-up server
- Set appropriate ping intervals (recommended: 30-60 seconds)
- Monitor the /metrics endpoint for server health
- Use environment variables for configuration
- Enable NODE_ENV=production in production environments
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
License
Support
For support, please open an issue in the GitHub repository or contact the maintainers.