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.
- 🔄 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
npm install @koding88/wakeup-render
# or
yarn add @koding88/wakeup-render- Create a
.envfile:
PORT=3000PING_URL=https://your-other-server.onrender.comNODE_ENV=production- Create a simple server:
require('dotenv').config();const{ createWakeUpServer }=require('@koding88/wakeup-render');constconfig={port: process.env.PORT||3000,pingUrl: process.env.PING_URL,interval: 30000// 30 seconds};createWakeUpServer(config);If you already have an Express application, you can run the wake-up server alongside it:
require('dotenv').config();constexpress=require('express');const{ createWakeUpServer }=require('@koding88/wakeup-render');// Your main Express appconstapp=express();app.get('/api/your-route',(req,res)=>{res.json({message: 'Hello from main app'});});// Start your main appapp.listen(4000,()=>{console.log('Main application running on port 4000');});// Start wake-up server on a different portconstwakeupConfig={port: process.env.WAKEUP_PORT||3000,pingUrl: process.env.PING_URL,interval: 30000};createWakeUpServer(wakeupConfig);| 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 |
GET /Response:
{
"status": "alive",
"lastPing": "2024-01-20T10:00:00.000Z",
"uptime": 3600
}GET /metricsResponse:
{
"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
}
}Create two servers on Render.com
For Server 1, set environment variables:
PORT=3000PING_URL=https://server2.onrender.comNODE_ENV=production- For Server 2, set environment variables:
PORT=3000PING_URL=https://server1.onrender.comNODE_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
- 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
The package uses Winston for logging with the following outputs:
- Console: Colored logs for development
- error.log: Error-level logs
- combined.log: All logs
- 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
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
For support, please open an issue in the GitHub repository or contact the maintainers.