Push Notifications API
Install everything in one command:
bash <(curl -fsSL https://raw.githubusercontent.com/Robmobius/push-notifications-api/main/quick-install.sh)This single command will:
- β Install system dependencies (build-essential)
- β Create 2GB swap file for memory management
- β Install Node.js (if not present)
- β Clone the repository
- β Install all Node.js dependencies
- β Run security audit fixes
- β Generate sample API key
- β Create .env configuration file
- β Display next steps
Perfect for VPS deployment!
If you prefer to download and inspect the script first:
# Download the script
wget https://raw.githubusercontent.com/Robmobius/push-notifications-api/main/quick-install.sh
# Make it executable
chmod +x quick-install.sh
# Run it
./quick-install.sh-
System Setup
- Updates package lists
- Installs build-essential for native compilation
- Creates 2GB swap file for memory management
-
Node.js Setup
- Installs Node.js LTS if not present
- Verifies Node.js installation
-
Application Setup
- Clones the repository from GitHub
- Installs all Node.js dependencies
- Runs
npm audit fixfor security
-
Configuration
- Generates secure API key
- Creates .env file with sample configuration
- Displays connection information
Ready to use in under 5 minutes!
You can download the Android app through Google Play or download the latest apk from the releases.
In the configuration tab type in the /events endpoint on your server
You can find the IP-address in the server log
The repository includes setup scripts for easy installation:
# Clone the repository
git clone https://github.com/Robmobius/push-notifications-api.git
cd push-notifications-api
# Run the complete setup script
chmod +x setup.sh
./setup.shThis script will:
- Install build-essential package
- Create a 2GB swap file (important for low-memory systems)
- Install Node.js dependencies
- Run security audit fixes
If you only need to set up the server environment:
cd push-notifications-api/server
chmod +x setup-server.sh
./setup-server.shIf you prefer manual setup, follow these steps:
sudo apt update
sudo apt install build-essentialsudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstabcd server
npm install
npm audit fixThe build-essential package provides:
- GCC compiler
- Make utility
- Development libraries
- Other essential build tools
These are required for compiling native Node.js addons that some dependencies may use.
If you haven't already, install Node.
git clone git@github.com:viktorholk/push-notifications-api.git
cd push-notifications-api/server
npm i
npm run start
The app will by default run on port 3000 and the endpoint for the notification events are /events
The port can be changed in the server/.env file
Replace 127.0.0.1:3000 with your IP and port
POST http://127.0.0.1:3000Example Curl
curl '127.0.0.1:3000' \
--header 'Content-Type: application/json' \
--data '{
"title": "Foo Bar Baz!",
"message": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
"url": "http://example.com",
"icon": "suitcase.png",
"color": "#1554F0"
}'
| Property | Type | Description | Required |
|---|---|---|---|
| title | String | The title of the notification | Yes |
| message | String | The longer text that will be included in the notification | No |
| url | String | Open the URL on notifcation press | No |
| icon | String | 24x24 icon file located in server/src/icons |
No |
| color | String | Customize the notification color. See supported colors | No |
Created 201
GET http://127.0.0.1:3000[
{
"title": "Foo Bar Baz!",
"message": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
"url": "http://example.com",
"icon": "base64encoded...",
"color": "#1554F0"
},
...
]
GET http://127.0.0.1:3000/latest{
"title": "Foo Bar Baz!",
"message": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
"url": "http://example.com",
"icon": "base64encoded...",
"color": "#1554F0"
}
Notifications are not showing up
Make sure notifications are enabled in your settings
Settings > Notifications > App notifications
Please report issues using GitHub's issues tab.
Push Notifications API is under the MIT LICENSE.
Problem Solved: The Android app connection was dropping after several minutes of inactivity.
Solution Implemented:
- β Keep-alive heartbeat system (30-second intervals)
- β Enhanced socket configuration with TCP keep-alive
- β Automatic cleanup of dead connections
- β Extended socket timeout (5 minutes)
- β Graceful shutdown handling
// Sends keep-alive messages every 30 seconds
const HEARTBEAT_INTERVAL = 30000;- Socket Timeout: Extended to 5 minutes (300,000ms)
- TCP Keep-Alive: Enabled at socket level with 30-second intervals
- Nagle's Algorithm: Disabled for better real-time performance
- Connection Validation: Automatic cleanup of broken connections
GET /healthResponse:
{
"status": "healthy",
"uptime": 12345.67,
"activeConnections": 3,
"totalNotifications": 42,
"timestamp": "2025-07-20T18:29:00.000Z"
}The server now actively manages connections with:
- Real-time monitoring of active connections
- Automatic cleanup of dead/broken connections
- Enhanced logging for connection events
- Connection state validation before sending data
Use the included test script to verify connection stability:
cd server
./test-connection.shThis will monitor the /events endpoint for 2 minutes and show keep-alive messages.
Before installing the Node server, ensure your system has the necessary build tools:
sudo apt update
sudo apt install build-essential# Run the included setup script
chmod +x setup.sh
./setup.shThe repository includes setup scripts for easy installation:
# Clone the repository
git clone https://github.com/Robmobius/push-notifications-api.git
cd push-notifications-api
# Run the complete setup script
chmod +x setup.sh
./setup.shThis script will:
- Install build-essential package
- Create a 2GB swap file (important for low-memory systems)
- Install Node.js dependencies
- Run security audit fixes
If you only need to set up the server environment:
cd push-notifications-api/server
chmod +x setup-server.sh
./setup-server.shIf you prefer manual setup, follow these steps:
sudo apt update
sudo apt install build-essentialsudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstabcd server
npm install
npm audit fixThe build-essential package provides:
- GCC compiler
- Make utility
- Development libraries
- Other essential build tools
These are required for compiling native Node.js addons that some dependencies may use.
The server now provides detailed logging:
[20/7/2025 18:26:41] INFO Server is running on http://127.0.0.1:3000
[20/7/2025 18:26:41] INFO Heartbeat interval: 30000ms
[20/7/2025 18:27:11] INFO Sent keep-alive to 192.168.1.100
[20/7/2025 18:27:11] INFO Active connections: 2
- Client connections and disconnections
- Keep-alive message delivery
- Connection cleanup operations
- Error handling and recovery
- Connection Drops: Resolved through keep-alive heartbeat mechanism
- Dead Connections: Automatic cleanup prevents memory leaks
- Network Timeouts: Extended socket timeouts handle mobile network behavior
- Error Handling: Improved error recovery for network issues
The improvements are transparent to the Android app:
- No app changes required
- Maintains existing API compatibility
- Enhanced connection stability
- Better handling of mobile network conditions
- Reduced Connection Overhead: Efficient keep-alive mechanism
- Better Resource Management: Automatic cleanup of dead connections
- Improved Logging: Better debugging and monitoring capabilities
- Graceful Shutdown: Proper resource cleanup on server termination
Node.js applications can be memory-intensive, especially during:
- npm package installation
- TypeScript compilation
- Running with multiple connections
Without adequate memory, you may encounter:
FATAL ERROR: Ineffective mark-compacts near heap limit- npm install failures
- Server crashes under load
- Prevents out-of-memory errors during installation
- Improves stability under high load
- Essential for VPS with limited RAM (1GB or less)
# Check current swap usage
swapon --show
# Check memory and swap status
free -hThe setup automatically runs npm audit fix to:
- Fix known security vulnerabilities
- Update packages to secure versions
For production environments, you can run the Push Notifications API as a systemd service to ensure automatic startup, restart on failure, and proper system integration.
# Run the automated installation script
sudo ./systemd/install-service.shIf you prefer manual installation:
-
Copy the service file:
sudo cp systemd/push-notifications.service /etc/systemd/system/
-
Edit paths in the service file (if needed):
sudo nano /etc/systemd/system/push-notifications.service # Update WorkingDirectory, ExecStart paths as needed -
Enable and start the service:
sudo systemctl daemon-reload sudo systemctl enable push-notifications.service sudo systemctl start push-notifications.service
# Check service status
sudo systemctl status push-notifications
# Start the service
sudo systemctl start push-notifications
# Stop the service
sudo systemctl stop push-notifications
# Restart the service
sudo systemctl restart push-notifications
# View logs
sudo journalctl -u push-notifications -f
# View log files
sudo tail -f /var/log/push-notifications.log
sudo tail -f /var/log/push-notifications-error.log- Auto-restart: Service automatically restarts if it crashes
- Boot startup: Service starts automatically on system boot
- Log management: Separate log files for output and errors
- Security: Runs with restricted permissions
- Monitoring: Easy status monitoring with systemctl
If the service fails to start:
-
Check service status:
sudo systemctl status push-notifications --no-pager
-
Check logs:
sudo journalctl -u push-notifications --no-pager -n 50
-
Verify Node.js and npm paths:
which node which npm
-
Test manual startup:
cd server && npm start
- Ensure production-ready deployment
The API supports optional API key authentication for enhanced security. When enabled, it protects your notification endpoints from unauthorized access.
# Add to server/.env
API_KEY=your-secure-api-key-here# Using OpenSSL
openssl rand -base64 32
# Using Node.js
node -e "console.log(require('crypto').randomBytes(32).toString('base64'))"
# Example result:
# sk_live_abc123def456ghi789jkl012mno345pqr678stu901vwx234yzThe API supports multiple authentication methods:
curl -X POST "http://your-server:3000/" \
-H "Content-Type: application/json" \
-H "X-API-Key: your-secure-api-key-here" \
-d '{"title": "Test Notification", "message": "Hello World!"}'curl -X POST "http://your-server:3000/" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-secure-api-key-here" \
-d '{"title": "Test Notification", "message": "Hello World!"}'curl -X POST "http://your-server:3000/?api_key=your-secure-api-key-here" \
-H "Content-Type: application/json" \
-d '{"title": "Test Notification", "message": "Hello World!"}'POST /- Create notificationGET /- Get all notificationsGET /latest- Get latest notification
GET /health- Health check and server statusGET /events- Server-Sent Events (SSE) connection*
*The /events endpoint supports optional authentication. If no API key is provided, access is allowed but logged with warnings.
To use authentication with your Android app, include the API key in your requests:
// In your Android app HTTP connection
connection.setRequestProperty("X-API-Key", "your-secure-api-key-here");// Append to your SSE connection URL
String url = "http://your-server:3000/events?api_key=your-secure-api-key-here";Check if authentication is enabled:
curl http://your-server:3000/healthResponse includes authentication status:
{
"status": "healthy",
"authentication": "enabled",
"activeConnections": 0,
"totalNotifications": 0
}{
"error": "Authentication required",
"message": "API key must be provided via X-API-Key header, Authorization: Bearer header, or api_key query parameter"
}{
"error": "Authentication failed",
"message": "Invalid API key provided"
}For detailed security documentation, see:
server/API_SECURITY.md- Complete authentication guide- Security best practices
- Production deployment recommendations
- Android app integration examples
To run without authentication (NOT recommended for production):
# Comment out or remove API_KEY from server/.env
# API_KEY=your-secure-api-key-hereServer will show warning:
β οΈ WARNING: API Key authentication is DISABLED - set API_KEY environment variable


