Prerequisites
Before you begin:
- A SpringEdge account with an API key
- Node.js 14 or higher installed
- Install axios:
npm install axios - A DLT-registered sender ID and approved template (for India)
Async/Await
Non-blocking API calls with modern JavaScript async patterns
Webhook Ready
Receive delivery reports with Express.js endpoints
npm Install
One dependency (axios) — or use built-in fetch in Node 18+
const axios = require('axios');
const API_KEY = 'YOUR_API_KEY';
const URL = 'https://api.springedge.com'
+ '/v1/sms/send';
async function sendSms(phone, message) {
const { data } = await axios.post(URL, {
to: phone,
sender_id: 'SPREDG',
message: message,
type: 'transactional',
}, {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${API_KEY}`,
},
timeout: 10000,
});
console.log('Status:', data.status);
console.log('Message ID:', data.message_id);
return data;
}
// Usage
sendSms('+919876543210', 'Your OTP is 482910')
.catch(console.error);
// Response:
// {
// "status": "success",
// "message_id": "msg_a1b2c3d4",
// "credits_used": 1
// }
AXIOS
Using axios
This example uses axios to send an SMS through the SpringEdge API with async/await. Install with npm install axios.
For Node.js 18+, you can also use the built-in fetch() API instead of axios — no external dependency needed.
Quick Start:
npm init -y && npm install axios- Replace
YOUR_API_KEYwith your SpringEdge key - Run:
node send_sms.js
EXPRESS.JS
Receive Delivery Reports
Set up an Express.js webhook endpoint to receive real-time delivery status updates. SpringEdge sends an HTTP POST to your configured URL whenever a message is delivered, fails, or is rejected.
Configure the webhook URL in your SpringEdge dashboard under Account Settings.
const express = require('express');
const app = express();
app.use(express.json());
app.post('/webhook/dlr', (req, res) => {
const { message_id, status, to } = req.body;
console.log(
`Message ${message_id} to `
+ `${to}: ${status}`
);
// Update your database
// await db.updateSmsStatus(
// message_id, status
// );
res.json({ ok: true });
});
app.listen(3000, () =>
console.log('Webhook server on :3000')
);
What You Can Build
OTP Verification
Add phone number verification to your Express, Nest.js, or Next.js signup and login flows.
Webhook Server
Build a real-time delivery tracking server that processes delivery reports and updates your database.
Scheduled Campaigns
Use node-cron or Bull queues to schedule and send bulk SMS campaigns at optimal delivery times.
Microservice Alerts
Send SMS alerts from your Node.js microservices when critical events occur — server down, threshold breached, deployment complete.
