Skip to main content

Prerequisites

Before you begin:

  • A SpringEdge account and API key (sign up free; the key is shared after sign-up, along with test credits)
  • Node.js 18 or later for the built-in fetch
  • Only if you use the package: npm install springedge
  • A DLT-registered sender ID and an approved template (needed for every SMS sent in India)

Official npm Package

springedge sends a message in one call

Delivery Reports

Receive delivery status on your own Express.js endpoint via callbackurl

Or Zero Dependencies

Use built-in fetch in Node 18+ with a form-encoded POST

// send_sms.js
const springedge = require('springedge');

const params = {
  apikey: 'YOUR_API_KEY',
  sender: 'SEDEMO',
  to: ['91XXXXXXXXXX'],
  message: 'Your OTP is 482910',
  format: 'json',
};

// 5000 = request timeout in milliseconds
springedge.messages.send(params, 5000, (err, response) => {
  if (err) {
    // Network failure or timeout
    console.error('Request failed:', err.message);
    process.exitCode = 1;
    return;
  }
  if (!response || !response.MessageIDs) {
    // e.g. {"error": "Invalid Mobile Numbers"}
    console.error('Not sent:', response);
    process.exitCode = 1;
    return;
  }
  console.log('Message ID:', response.MessageIDs);
});

// Accepted (format=json):
// {"groupID": 61, "MessageIDs": "61-1",
//  "status": "AWAITED-DLR"}

NPM PACKAGE

Using the springedge Package

springedge is our own Node.js library. Give it your apikey, sender ID, recipient list and message (word for word as in your DLT-approved template), and it calls your callback with the parsed result. A MessageIDs value means the message was accepted; an error field tells you why not.

Quick Start:

  1. npm init -y && npm install springedge
  2. Put your API key in place of YOUR_API_KEY
  3. Run: node send_sms.js

Without the package (Node 18+ fetch):

For new projects we suggest this version: no dependency, HTTPS straight to the SpringEdge SMS API, and you decide what happens on errors. Save it as send_sms.mjs and run node send_sms.mjs.

// send_sms.mjs (Node.js 18+, no packages)
const API_URL = 'https://web.springedge.com/api/web/send/';

async function sendSms(to, message) {
  const res = await fetch(API_URL, {
    method: 'POST',
    // URLSearchParams = form-encoded body, not JSON
    body: new URLSearchParams({
      apikey: 'YOUR_API_KEY',
      sender: 'SEDEMO',
      to,
      message,
      format: 'json',
    }),
    signal: AbortSignal.timeout(30_000),
  });

  const text = (await res.text()).trim();
  let data = null;
  try {
    data = JSON.parse(text);
  } catch {
    // Not JSON: an error message as text
  }

  if (!res.ok || !data?.MessageIDs) {
    // e.g. "Invalid Sender ID"
    throw new Error(`SMS not sent (HTTP ${res.status}): ${text}`);
  }
  return data.MessageIDs; // e.g. "61-1"
}

sendSms('91XXXXXXXXXX', 'Your OTP is 482910')
  .then((id) => console.log('Message ID:', id))
  .catch((err) => {
    console.error(err.message);
    process.exitCode = 1;
  });

All parameters are in the SMS API documentation. Call the API only from server-side code. In a browser bundle or a mobile app the key is visible to anyone who looks, and they can spend your credits.

EXPRESS.JS

Receive Delivery Reports

To know whether each message reached the phone, add callbackurl (your endpoint) and label (your own reference, such as an order number) to the send parameters. When the operator reports back, SpringEdge calls your URL with label, recipient and status: DELIVRD, UNDLIVRD or FAILED.

Answer with HTTP 200 straight away and do the database work after. The endpoint must be reachable from the internet, so use a tunnel while testing locally. Details are in delivery report webhooks.

const express = require('express');
const app = express();

// Parameters may arrive as query string
// or form-encoded body
app.use(express.urlencoded({ extended: false }));

app.all('/webhook/dlr', (req, res) => {
  const p = { ...req.query, ...req.body };
  const { label, recipient, status } = p;

  console.log(`${label} to ${recipient}: ${status}`);

  // Update your database
  // await db.updateSmsStatus(label, status);

  res.sendStatus(200);
});

app.listen(3000, () =>
  console.log('DLR server on :3000')
);

// Send with: callbackurl:
//   'https://example.com/webhook/dlr',
// label: 'order-1001'

What You Can Build

OTP Verification

Send a six-digit code from an Express, Nest.js or Next.js API route at sign-up or login, and check it against a hash you stored with an expiry.

Webhook Server

Record every delivery report against its label, so support can see whether a customer's OTP or order SMS actually arrived.

Scheduled Campaigns

Queue campaign messages in BullMQ or schedule them with node-cron, with modest concurrency and a backoff on HTTP 429 or 5xx, inside the promotional sending hours.

Microservice Alerts

Text the on-call engineer when a service goes down, a queue backs up or a deployment fails.