Back to Documentation
JavaScript Integration
Send push notifications from any JavaScript environment - browser, Node.js, or serverless functions. The examples use the native fetch API which works everywhere.
Browser / Basic Example
const response = await fetch('https://thenotification.app/api/sendNotification', {
method: 'POST',
headers: {
'app_key': 'YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
title: 'New Message',
body: 'Check out this notification',
link: 'https://example.com/page',
image: 'https://picsum.photos/400/200'
})
});
const result = await response.json();
console.log(result);Node.js Example
// Using Node.js with node-fetch
import fetch from 'node-fetch';
async function sendNotification() {
const response = await fetch('https://thenotification.app/api/sendNotification', {
method: 'POST',
headers: {
'app_key': process.env.NOTIFICATION_API_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify({
title: 'Server Alert',
body: 'Your deployment was successful!'
})
});
return response.json();
}Response Handling
// Success response
{
"success": true,
"message": "Notification sent to 1 device(s)",
"devices_sent": 1,
"failed_count": 0
}
// Error response
{
"success": false,
"error": "Invalid app_key"
}Tip: Store your API key in environment variables and never expose it in client-side code. For browser apps, make the API call from your backend.