Send OTP without DLT in Node.js and Express

To send OTP without DLT in Node.js, call DiOTP's /v1/otp/send endpoint with the built-in fetch, keep the returned request_id in the user's session, and post it with the typed code to /v1/otp/verify. The SMS goes out on DiOTP's registered DIORBT header and pre-approved OTP template, so you register nothing with DLT. The same code keeps working when you add your own sender ID later.

By , Founder, Diorbit TechnologiesUpdated

Key facts

Price
₹0.26 to ₹0.40 per OTP plus 18% GST, from a prepaid wallet. No setup fee, no monthly fee.
Setup time
Same day. Test on your own number in minutes, then go live.
Sender name
DIORBT, DiOTP's registered header (shown with an operator prefix, for example VM-DIORBT).
Message
"123456 is your login OTP for Your Company. Do not share it with anyone. Powered by Diorbit Technologies!" The wording is fixed; your company name fills the name slot.
Compliance
Sent under DiOTP's own registered DLT entity, header and pre-approved OTP template. You register nothing.
Limits per number
1 code every 30 seconds, 3 per hour, 10 per day.
Later
Move to your own sender ID when your DLT registration is ready, with no code changes.

Who is this Node.js guide for?

You run a Node.js backend, you need OTP login or signup verification now, and your own DLT registration is not ready. OTP without DLT on DiOTP covers exactly that gap. Your codes are sent under DiOTP's own registered DLT entity, from the DIORBT header, on a pre-approved OTP template. You can be live the same day.

This page is the quickest setup: what your users will see, a small fetch client, the errors you meet on a trial and on the shared template, an Express Router with one error middleware that maps every code, and the move to your own sender ID with no code change. For the verify side in depth, with sessions, per-IP rate limits, signed webhooks and automated tests, read OTP verification in Node.js.

All code here uses plain HTTP through Node's built-in fetch, so there is nothing to install from DiOTP. If you prefer a library, the official Node.js SDK is installed with npm install @diorbit/diotp and imported from 'diotp'; it is described on the SDKs page.

What message does the shared template send?

Design your screens around the message your users will actually get. On the shared template the sender is DIORBT, shown with an operator prefix such as VM-DIORBT, and the words are fixed:

Text message

VM-DIORBT

482913 is your login OTP for Acme. Do not share it with anyone. Powered by Diorbit Technologies!

What your users receive: the code first, then your company name, from DIORBT.
  • Only the code and your company name change. The company name holds up to 30 characters.
  • The text says "login OTP", so use it for login and signup. Delivery codes, appointment checks or payment confirmations read better on your own template.
  • Order updates, reminders, alerts and promotions always need your own DLT registration. The shared template is for OTPs only.

Tell users in your UI that the code comes from DIORBT, next to the code box. People who expect your brand name as the sender may otherwise ignore the message. You can check how your name fits with the OTP message preview tool.

How do you send OTP without DLT in Node.js, step by step?

  1. Create a DiOTP account and an API key. You get 10 free test messages, sent only to the mobile number you verified at sign-up.
  2. Set DIOTP_API_KEY and SESSION_SECRET as environment variables on your server. Use Node 18 or newer so fetch and AbortSignal.timeout are built in.
  3. Install Express and a session middleware: npm install express express-session.
  4. Add lib/diotp.js and lib/otp-errors.js from this page, then the router in routes/otp.js.
  5. Mount the router at /auth/otp in app.js, behind the session middleware.
  6. Test the full flow on your own number, then recharge your wallet so the same key sends to any Indian mobile number.

A small fetch client with a typed error

The client has two exported functions and one error class. Any failure, from a 4xx reply to a dropped connection, becomes a DiotpError with a status and a stable code, so the rest of your app has one thing to catch. The 8 second timeout uses AbortSignal.timeout, so a slow network never holds an Express request open.

lib/diotp.js

// lib/diotp.js  (Node 18 or newer: fetch is built in, no packages needed)
import { randomUUID } from "node:crypto";

const BASE = "https://api-diotp.diorbit.com/v1";

export class DiotpError extends Error {
  constructor(status, code, message) {
    super(status + " " + code + ": " + (message || ""));
    this.status = status;
    this.code = code;
  }
}

async function post(path, body, headers = {}) {
  let res;
  try {
    res = await fetch(BASE + path, {
      method: "POST",
      headers: {
        Authorization: "Bearer " + process.env.DIOTP_API_KEY,
        "Content-Type": "application/json",
        ...headers,
      },
      body: JSON.stringify(body),
      signal: AbortSignal.timeout(8000),
    });
  } catch {
    throw new DiotpError(0, "network_error", "No response from DiOTP");
  }
  const data = await res.json().catch(() => ({}));
  if (!res.ok) {
    throw new DiotpError(res.status, data.error?.code ?? "unknown", data.error?.message);
  }
  return data;
}

export async function sendCode(phone, { purpose = "login", key = randomUUID() } = {}) {
  const body = { to: phone, country_code: 91, channel: "sms", purpose };
  const data = await post("/otp/send", body, { "Idempotency-Key": key });
  return { requestId: data.request_id, expiresAt: data.expires_at };
}

export async function checkCode(requestId, code) {
  const data = await post("/otp/verify", { request_id: requestId, code: String(code) });
  return data.verified === true;
}

sendCode takes an Idempotency-Key from the caller. That matters for retries: if the router retries the same tap with the same key, DiOTP returns the first answer and sends nothing new, so nobody gets two codes. The function returns only the request_id and expiry. The code itself is generated and stored by DiOTP; your server never sees it.

If you want to compare with the raw calls, here they are, with a Node.js tab:

curl -X POST https://api-diotp.diorbit.com/v1/otp/send \
  -H "Authorization: Bearer $DIOTP_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: 5f2b8c1e-signup-9876543210" \
  -d '{
    "to": "9876543210",
    "country_code": 91,
    "channel": "sms",
    "purpose": "signup"
  }'
curl -X POST https://api-diotp.diorbit.com/v1/otp/verify \
  -H "Authorization: Bearer $DIOTP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_id": "7c9e6679-7425-40de-944b-e07fc1f90ae7",
    "code": "482913"
  }'

How do you map DiOTP error codes in Node.js?

Put every code in one table, and give each a kind. User errors get a friendly message and the right HTTP status. Retry errors are tried again with the same key. Ops errors are problems with your setup or account, which a visitor cannot fix, so you log them and show a generic message.

lib/otp-errors.js

// lib/otp-errors.js: one table, three kinds of error.
// "user": show the text. "retry": safe to try again with the same key. "ops": alert your team.
export const OTP_ERRORS = {
  resend_cooldown:      { kind: "user",  http: 429, text: "Please wait 30 seconds before asking for another code." },
  phone_hourly_limit:   { kind: "user",  http: 429, text: "Too many codes for this number. Try again in an hour." },
  phone_daily_limit:    { kind: "user",  http: 429, text: "Too many codes for this number today. Try tomorrow." },
  invalid_request:      { kind: "user",  http: 400, text: "Enter a valid 10 digit mobile number." },
  invalid_code:         { kind: "user",  http: 400, text: "That code is not right. Check the SMS and try again." },
  expired:              { kind: "user",  http: 410, text: "That code has expired. Ask for a new one." },
  not_pending:          { kind: "user",  http: 409, text: "That code can no longer be used. Ask for a new one." },
  too_many_attempts:    { kind: "user",  http: 429, text: "Too many wrong tries. Ask for a new code." },
  sending_unavailable:  { kind: "retry" },
  rate_limited:         { kind: "retry" },
  api_key_minute_limit: { kind: "retry" },
  network_error:        { kind: "retry" },
  trial_restricted:     { kind: "ops", note: "test mode: only your verified number receives codes" },
  trial_used_up:        { kind: "ops", note: "the 10 free test messages are spent: recharge to go live" },
  insufficient_balance: { kind: "ops", note: "wallet is empty: recharge" },
  unauthorized:         { kind: "ops", note: "API key missing, wrong or revoked" },
  account_suspended:    { kind: "ops", note: "account suspended" },
  channel_not_enabled:  { kind: "ops", note: "channel not enabled on this account" },
  template_not_available: { kind: "ops", note: "leave template out to use the shared template" },
};

export function describe(code) {
  return OTP_ERRORS[code] ?? { kind: "ops", note: "unknown code " + code };
}

The errors you will meet on a trial

trial_restricted (403) means you sent to a number other than your own verified one while in test mode. Your code is fine; that is how test mode works. trial_used_up (402) means the 10 free test messages are spent. Both disappear once you recharge your wallet, which makes the account live.

The errors you will meet on the shared template

template_not_available (422) means you passed a template id your account cannot use. On the shared template, simply leave template out. channel_not_enabled (409) means you sent channel whatsapp and WhatsApp is not enabled on your account; WhatsApp OTP is live on the same API but is enabled per account.

The errors every user can hit

resend_cooldown (one code every 30 seconds per number), phone_hourly_limit (3 per hour) and phone_daily_limit (10 per day) on send. On verify: invalid_code, expired (codes last 5 minutes), not_pending and too_many_attempts (after 5 wrong tries). Codes blocked by a rate limit are not sent or charged. The status for every code is in the API reference for OTP without DLT.

An Express router with send and verify routes

The router keeps the whole OTP flow in one file. The send route cleans the number, makes one Idempotency-Key for the tap and retries only the retry kind of error, at most three times. The request_id goes into req.session.otp, so each browser session has its own pending code and the client never handles the request_id at all.

routes/otp.js

// routes/otp.js: an Express router you mount at /auth/otp
import { Router } from "express";
import { randomUUID } from "node:crypto";
import { DiotpError, sendCode, checkCode } from "../lib/diotp.js";
import { describe } from "../lib/otp-errors.js";

export const otpRouter = Router();
const wait = (ms) => new Promise((r) => setTimeout(r, ms));

otpRouter.post("/send", async (req, res, next) => {
  const phone = String(req.body.phone ?? "").replace(/\D/g, "").slice(-10);
  const key = randomUUID(); // one key for this tap, reused on every retry below

  for (let attempt = 1; attempt <= 3; attempt++) {
    try {
      const { requestId, expiresAt } = await sendCode(phone, { purpose: "login", key });
      req.session.otp = { requestId, phone }; // stays on the server, per session
      return res.json({ sent: true, expiresAt });
    } catch (err) {
      if (!(err instanceof DiotpError)) return next(err);
      if (describe(err.code).kind === "retry" && attempt < 3) {
        await wait(attempt * 500);
        continue;
      }
      return next(err);
    }
  }
});

otpRouter.post("/verify", async (req, res, next) => {
  const pending = req.session.otp;
  if (!pending) return res.status(400).json({ error: "no_code", message: "Ask for a code first." });
  try {
    await checkCode(pending.requestId, req.body.code ?? "");
  } catch (err) {
    if (!(err instanceof DiotpError) || err.code !== "already_verified") return next(err);
  }
  delete req.session.otp;
  req.session.regenerate((err) => {
    if (err) return next(err);
    req.session.verifiedPhone = pending.phone;
    res.json({ verified: true });
  });
});

// Error middleware for this router: every DiOTP error ends up here.
otpRouter.use((err, req, res, next) => {
  if (!(err instanceof DiotpError)) return next(err);
  const info = describe(err.code);
  if (info.kind === "user") {
    return res.status(info.http).json({ error: err.code, message: info.text });
  }
  // Setup, account or repeated network problems: log for your team, never the key.
  console.error("[otp]", err.status, err.code, info.note ?? "");
  res.status(503).json({ error: "otp_unavailable", message: "We could not send a code right now. Please try again shortly." });
});

Look at the last block. It is error middleware attached to the router, so any DiOTP error thrown in either route reaches one place. User errors go back with their own status and text. Everything else is logged with the status and code, never the API key, and the visitor sees a generic otp_unavailable.

The verify route treats already_verified as success, so a double tap on the submit button does not show an error. On success it regenerates the session, which gives the visitor a fresh session id the moment they gain access.

app.js

// app.js
import express from "express";
import session from "express-session";
import { otpRouter } from "./routes/otp.js";

const app = express();
app.use(express.json());
app.use(session({
  secret: process.env.SESSION_SECRET,
  resave: false,
  saveUninitialized: false,
  cookie: { httpOnly: true, sameSite: "lax", secure: process.env.NODE_ENV === "production" },
}));

app.use("/auth/otp", otpRouter);
app.listen(process.env.PORT ?? 3000);

Before production, swap the default memory session store for a shared one, and add a per-IP limit and a bot check on the send route; our guide to SMS pumping protection explains why.

What changes in your Node.js code when you get your own sender ID?

Nothing. When your DLT registration is approved, add your entity ID, header and template ID under Sender IDs in the DiOTP dashboard. lib/diotp.js, the error table and the router all stay exactly the same, and codes start going out under your own header and wording. You can keep sending on the shared template while your registration is in review.

Your own template also lets you use wording other than "login OTP" and, for Android apps, include the app hash that SMS Retriever autofill needs. Until then, the price is the same either way: ₹0.26 to ₹0.40 per OTP plus 18% GST, from a prepaid wallet, with no setup or monthly fee. The DLT registration guide covers the paperwork when you are ready.

Questions and answers

Do I need DLT registration to send OTP from Node.js?

Not with DiOTP. Codes are sent under DiOTP's registered DLT entity, the DIORBT header and a pre-approved OTP template. You need an account and an API key.

Is there a DiOTP npm package?

Yes: the official Node.js SDK is the diotp package, installed with npm install @diorbit/diotp. You do not need it: the API is two HTTPS POST requests, which Node 18 and newer can make with the built-in fetch and no extra packages.

Why do I get trial_restricted from my Express app?

Your account is in test mode, and test messages go only to the mobile number you verified at sign-up. Use that number while testing, or recharge your wallet to go live.

Which DiOTP errors should my Node.js code retry?

Only sending_unavailable, rate_limited, api_key_minute_limit and network failures, with the same Idempotency-Key and short waits. Other errors give the same answer on a retry.

Where should the request_id live?

On the server, in the user's session. The browser never needs it, so nobody can submit a code against a request that belongs to someone else.

Will my Node.js code change when I move to my own sender ID?

No. You add your entity ID, header and template ID under Sender IDs in the dashboard, and the same send and verify calls keep working.

Send your first OTP today.

Free test credits on sign-up, API keys in a minute, and a team that picks up the phone.