{"id":18050,"date":"2026-11-18T23:45:47","date_gmt":"2026-11-18T18:15:47","guid":{"rendered":"https:\/\/www.fast2sms.com\/help\/nodejs-sms-api\/"},"modified":"2026-11-19T00:50:35","modified_gmt":"2026-11-18T19:20:35","slug":"nodejs-sms-api","status":"publish","type":"post","link":"https:\/\/www.fast2sms.com\/help\/nodejs-sms-api\/","title":{"rendered":"Send SMS and OTP in Node.js with Fast2SMS API (fetch \/ axios)"},"content":{"rendered":"<p>This guide shows how to send SMS and OTP from Node.js with the Fast2SMS API. It uses the <code>fetch<\/code> that is built into Node.js 18 and later, so you install nothing extra (an axios version is included too). You will send a DLT SMS, send and verify an OTP with <a href=\"\/help\/smart-otp-setup-guide-fast2sms\/\">Smart OTP<\/a>, get delivery reports in an Express webhook, and handle errors safely. A complete module is at the end.<\/p>\n<aside class=\"f2s-cta\" aria-label=\"Get started with Fast2SMS\"><div class=\"f2s-cta__copy\"><strong class=\"f2s-cta__title\">Send SMS from Node.js<\/strong><p>Copy your API key, pick your DLT or Smart OTP template and send your first message from Node.js.<\/p><\/div><div class=\"f2s-cta__actions\"><a class=\"f2s-cta__btn f2s-cta__btn--primary\" href=\"https:\/\/www.fast2sms.com\/\"><span>Sign up free<\/span> <span class=\"f2sh-btn__arrow\" aria-hidden=\"true\">&rarr;<\/span><\/a><a class=\"f2s-cta__btn f2s-cta__btn--ghost\" href=\"https:\/\/www.fast2sms.com\/meet\/\" target=\"_blank\" rel=\"noopener\">Book a free meeting<\/a><\/div><\/aside>\n<h2>Before you start<\/h2>\n<ul>\n<li><strong>Node.js 18 or later<\/strong> (for built-in <code>fetch<\/code>). On older versions, use the axios example.<\/li>\n<li><strong>API key<\/strong> from <strong>API Key<\/strong> under UTILITY, with <strong>API Access<\/strong> on.<\/li>\n<li><strong>DLT SMS:<\/strong> an approved sender ID and template in <strong>DLT Manager<\/strong>, and the template&#8217;s <strong>Message ID<\/strong>.<\/li>\n<li><strong>OTP:<\/strong> a Smart OTP template and its <strong>OTP ID<\/strong> from <strong>OTP Template List<\/strong>.<\/li>\n<li><strong>Wallet balance.<\/strong> Each SMS, OTP send and resend is charged.<\/li>\n<li><strong>Backend only.<\/strong> Run this in Node.js on your server. Never put the key in React, Vue, React Native or any browser bundle.<\/li>\n<\/ul>\n<h2>Collect the IDs from the panel<\/h2>\n<ol class=\"f2s-steps\">\n<li>\n<h3>Copy the API key<\/h3>\n<p>Open <strong>Account Setting<\/strong>, then <strong>API Key<\/strong>. Click <strong>View<\/strong>, type the OTP sent to your account mobile, then copy the <strong>Authorization Key<\/strong>.<\/p>\n<figure class=\"f2s-shot\"><img src=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/api-key-hd-11-scaled.webp\" width=\"1440\" height=\"900\" loading=\"lazy\" decoding=\"async\" alt=\"API Key page with masked Authorization Key, View and Reset buttons, API Access and Quick API Access switches\"><figcaption>Store this key in an environment variable.<\/figcaption><\/figure>\n<\/li>\n<li>\n<h3>Copy the Message ID and sender ID<\/h3>\n<p>Open <strong>DLT Manager<\/strong>, <strong>Content Template<\/strong>. Copy the <strong>Message ID<\/strong> and <strong>Sender ID<\/strong> from the same approved template card.<\/p>\n<figure class=\"f2s-shot\"><img src=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/sms-dlt-template-list-hd-13-scaled.webp\" width=\"1440\" height=\"900\" loading=\"lazy\" decoding=\"async\" alt=\"Approved DLT content template cards with Message ID, Sender ID, Template ID and Entity rows\"><figcaption>Message ID is what the API calls message.<\/figcaption><\/figure>\n<\/li>\n<li>\n<h3>Copy the OTP ID<\/h3>\n<p>Open Smart OTP, <strong>OTP Template List<\/strong>, and copy the <strong>OTP ID<\/strong> from the card you want.<\/p>\n<figure class=\"f2s-shot\"><img src=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/smart-otp-template-list-hd-8-scaled.webp\" width=\"1440\" height=\"900\" loading=\"lazy\" decoding=\"async\" alt=\"Smart OTP Template cards for WhatsApp and SMS with OTP ID, sender or number, template ID and fallback\"><figcaption>Copy the OTP ID with the icon next to it.<\/figcaption><\/figure>\n<\/li>\n<\/ol>\n<h2>Set up the project<\/h2>\n<pre><code class=\"language-bash\">mkdir sms-demo &amp;&amp; cd sms-demo\nnpm init -y\nnpm install express            # only needed for the webhook receiver\nexport FAST2SMS_API_KEY=\"YOUR_API_KEY\"<\/code><\/pre>\n<p>Add <code>\"type\": \"module\"<\/code> to <code>package.json<\/code> to use <code>import<\/code>. With a <code>.env<\/code> file, Node.js 20.6 and later can load it with <code>node --env-file=.env app.js<\/code>.<\/p>\n<p>A small helper for every call:<\/p>\n<pre><code class=\"language-javascript\">const BASE_URL = \"https:\/\/www.fast2sms.com\";\nconst API_KEY = process.env.FAST2SMS_API_KEY;\n\nexport async function f2sPost(path, body) {\n  const res = await fetch(BASE_URL + path, {\n    method: \"POST\",\n    headers: {\n      authorization: API_KEY,\n      \"Content-Type\": \"application\/json\",\n      Accept: \"application\/json\",\n    },\n    body: JSON.stringify(body),\n    signal: AbortSignal.timeout(15000),\n  });\n  let data;\n  try {\n    data = await res.json();\n  } catch {\n    return { ok: false, http: res.status, data: { message: \"Non-JSON response\" } };\n  }\n  return { ok: res.ok &amp;&amp; data.return === true, http: res.status, data };\n}<\/code><\/pre>\n<div class=\"f2s-note\">The header value is the bare key. Do not write <code>Bearer ${API_KEY}<\/code>. The OTP endpoints do not remove &#8220;Bearer &#8221; and answer &#8220;Invalid authorization key&#8221;.<\/div>\n<h2>Send a DLT SMS<\/h2>\n<p>Send to <code>\/dev\/bulkV2<\/code> with <code>route: \"dlt\"<\/code>. The example template is Message ID 10001 on sender DEMOTR with four variables.<\/p>\n<pre><code class=\"language-javascript\">const { ok, http, data } = await f2sPost(\"\/dev\/bulkV2\", {\n  route: \"dlt\",\n  sender_id: \"DEMOTR\",                                  \/\/ exact case\n  message: \"10001\",                                     \/\/ Message ID from DLT Manager\n  variables_values: [\"Rahul\", \"DT10458\", \"1240\", \"21 Nov\"].join(\"|\"),\n  numbers: [\"9999999999\", \"8888888888\"].join(\",\"),\n  udf1: \"order-DT10458\",                                \/\/ optional, returned in webhooks\n});\n\nif (ok) {\n  console.log(\"Queued:\", data.request_id);              \/\/ S...\n} else {\n  console.error(\"Not sent:\", data.status_code ?? http, data.message);\n}<\/code><\/pre>\n<ul>\n<li>One value per <code>{#var#}<\/code>, in order, joined with <code>|<\/code>. Each value is cut to 40 characters.<\/li>\n<li>The reply&#8217;s <code>message<\/code> is an array, <code>[\"SMS sent successfully.\"]<\/code>, which means queued.<\/li>\n<li>To send later, add <code>schedule_time: \"25-11-2026-10-30\"<\/code> (DD-MM-YYYY-HH-MM, IST) or a Unix timestamp.<\/li>\n<\/ul>\n<h3>Same call with axios<\/h3>\n<pre><code class=\"language-javascript\">import axios from \"axios\";\n\nconst { data } = await axios.post(\n  \"https:\/\/www.fast2sms.com\/dev\/bulkV2\",\n  { route: \"dlt\", sender_id: \"DEMOTR\", message: \"10001\",\n    variables_values: \"Rahul|DT10458|1240|21 Nov\", numbers: \"9999999999\" },\n  { headers: { authorization: process.env.FAST2SMS_API_KEY }, timeout: 15000,\n    validateStatus: () =&gt; true }   \/\/ read error bodies instead of throwing\n);\nconsole.log(data.return ? data.request_id : data.message);<\/code><\/pre>\n<p><code>validateStatus: () =&gt; true<\/code> stops axios from throwing on 400 and 401, so you can read Fast2SMS&#8217;s error message.<\/p>\n<h2>Send, verify and resend an OTP<\/h2>\n<p>Smart OTP creates the code and checks it, so your Node.js app does not need to store OTPs.<\/p>\n<pre><code class=\"language-javascript\">\/\/ 1. Send\nconst sent = await f2sPost(\"\/dev\/otp\/send\", {\n  mobile: \"9999999999\",\n  otp_id: \"YOUR_OTP_ID\",\n  otp_expiry: 5,     \/\/ minutes, 1 to 10080, default 15\n  otp_length: 6,     \/\/ 4 to 10, default 6\n});\nconsole.log(sent.ok ? \"OTP sent\" : sent.data.message);\n\n\/\/ 2. Verify the code the user typed\nconst check = await f2sPost(\"\/dev\/otp\/verify\", { mobile: \"9999999999\", otp: \"482913\" });\nif (check.ok) {\n  console.log(\"Verified\");               \/\/ create the session here\n} else {\n  console.log(check.data.message);       \/\/ Invalid OTP, OTP expired, ...\n}\n\n\/\/ 3. Resend the same OTP (charged again)\nconst again = await f2sPost(\"\/dev\/otp\/resend\", { mobile: \"9999999999\" });\nconsole.log(again.ok ? \"Sent again\" : again.data.message);<\/code><\/pre>\n<ul>\n<li>Verify needs only the mobile and code. It checks the latest unverified OTP for that number.<\/li>\n<li>A new send to the same number cancels older OTPs. Send only when the user taps the button.<\/li>\n<li>Resend repeats the same code. It works up to 10 minutes after the first send and 5 sends in total, counting the first.<\/li>\n<li>Too soon? You get &#8220;Please wait N seconds before requesting a new OTP&#8221;. The wait is in <strong>OTP Settings<\/strong> (default 10 seconds).<\/li>\n<\/ul>\n<h2>Delivery status: DLR API or webhook<\/h2>\n<p>Use one method per message flow. Fetching a DLR by API can stop the webhook from sending those rows later.<\/p>\n<h3>DLR API<\/h3>\n<pre><code class=\"language-javascript\">async function deliveryReport(requestId) {\n  const res = await fetch(`https:\/\/www.fast2sms.com\/dev\/dlr\/${encodeURIComponent(requestId)}`, {\n    headers: { authorization: process.env.FAST2SMS_API_KEY },\n    signal: AbortSignal.timeout(15000),\n  });\n  const data = await res.json();\n  if (&#33;data.success) return [];\n  return data.data[0].delivery_status.map((r) =&gt; ({ mobile: r.mobile, status: r.status }));\n}\n\nconsole.log(await deliveryReport(\"Sa1B2c3D4e5F6g7\"));  \/\/ Delivered \/ Failed \/ Sent<\/code><\/pre>\n<h3>Express webhook receiver<\/h3>\n<p>Create a webhook in the panel under <strong>Webhook<\/strong>, <strong>SMS<\/strong> or <strong>OTP<\/strong>, with format <strong>Standard Webhook<\/strong>, method POST, content type JSON and your public URL. Each attempt then shows in <strong>Webhook Logs<\/strong>.<\/p>\n<figure class=\"f2s-shot\"><img src=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/webhook-logs-hd-1-scaled.webp\" width=\"1440\" height=\"900\" loading=\"lazy\" decoding=\"async\" alt=\"Webhook Logs list with SMS and WhatsApp rows, POST method, DELIVERED and FAILED events, URL, response time, HTTP code and Success or Failed status\"><figcaption>Webhook Logs show the HTTP code your server returned.<\/figcaption><\/figure>\n<pre><code class=\"language-javascript\">import express from \"express\";\n\nconst app = express();\napp.use(express.json());\n\napp.post(\"\/fast2sms\/webhook\", (req, res) =&gt; {\n  \/\/ Optional: a header you added in the webhook's Headers tab\n  if (req.get(\"X-Webhook-Token\") &#33;== process.env.MY_WEBHOOK_TOKEN) {\n    return res.sendStatus(401);\n  }\n  const { request_id, mobile, status, status_description, udf1 } = req.body;\n  \/\/ status is \"delivered\" or \"failed\". Save it, then answer fast.\n  console.log(request_id, mobile, status, status_description, udf1);\n  res.sendStatus(200);\n});\n\napp.listen(3000);<\/code><\/pre>\n<p>Answer within 10 seconds. If your server times out or returns 408, 429 or 5xx, Fast2SMS tries again up to 3 times, 60 seconds apart. Webhooks fire only for API sends, for reports that come within 24 hours.<\/p>\n<aside class=\"f2s-cta\" aria-label=\"Get started with Fast2SMS\"><div class=\"f2s-cta__copy\"><strong class=\"f2s-cta__title\">Get live delivery status in Node.js<\/strong><p>Create one webhook and receive delivered and failed status for every SMS and OTP sent by API.<\/p><\/div><div class=\"f2s-cta__actions\"><a class=\"f2s-cta__btn f2s-cta__btn--primary\" href=\"https:\/\/www.fast2sms.com\/\"><span>Sign up free<\/span> <span class=\"f2sh-btn__arrow\" aria-hidden=\"true\">&rarr;<\/span><\/a><a class=\"f2s-cta__btn f2s-cta__btn--ghost\" href=\"https:\/\/www.fast2sms.com\/meet\/\" target=\"_blank\" rel=\"noopener\">Book a free meeting<\/a><\/div><\/aside>\n<h2>Error handling<\/h2>\n<ul>\n<li><strong>Check <code>data.return<\/code>.<\/strong> A low balance can reply HTTP 200 with <code>return: false<\/code> and status_code 416.<\/li>\n<li><strong>No automatic retries on sends.<\/strong> If a request times out after it reached Fast2SMS, retrying can send and charge twice. Retry once only for connection errors such as <code>ECONNREFUSED<\/code> or DNS failures. Verify is free and safe to retry once.<\/li>\n<li><strong>Use a timeout<\/strong> (<code>AbortSignal.timeout<\/code>) so a slow network does not hang your request handler.<\/li>\n<li><strong>Check API Logs<\/strong> in the panel to see what your code really sent in the last 7 days.<\/li>\n<\/ul>\n<div class=\"f2s-facts\">\n<table>\n<thead>\n<tr>\n<th>Reply<\/th>\n<th>Fix<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>412 Invalid Authentication, Check Authorization Key<\/td>\n<td>Copy the current key from <strong>API Key<\/strong>. The env variable may be empty.<\/td>\n<\/tr>\n<tr>\n<td>Invalid authorization key (OTP)<\/td>\n<td>Remove &#8220;Bearer &#8221; and check the key.<\/td>\n<\/tr>\n<tr>\n<td>413 Authorization Key Disabled<\/td>\n<td>Turn <strong>API Access<\/strong> on.<\/td>\n<\/tr>\n<tr>\n<td>414 IP is blacklisted from Dev API section<\/td>\n<td>Whitelist your server&#8217;s public IP in <strong>API Security<\/strong>. Serverless platforms change IPs often.<\/td>\n<\/tr>\n<tr>\n<td>406 Invalid Sender ID<\/td>\n<td>Use the approved sender in the exact case.<\/td>\n<\/tr>\n<tr>\n<td>424 Invalid Message ID<\/td>\n<td>Use the Message ID (not the 19-digit Template ID) linked to that sender.<\/td>\n<\/tr>\n<tr>\n<td>411 Invalid Numbers<\/td>\n<td>Use 10-digit Indian mobiles starting with 6 to 9.<\/td>\n<\/tr>\n<tr>\n<td>416 You don&#8217;t have sufficient wallet balance<\/td>\n<td>Recharge.<\/td>\n<\/tr>\n<tr>\n<td>Invalid OTP ID<\/td>\n<td>Copy the OTP ID again from the same account.<\/td>\n<\/tr>\n<tr>\n<td>Please wait N seconds before requesting a new OTP<\/td>\n<td>Show a timer on the Resend button.<\/td>\n<\/tr>\n<tr>\n<td>Invalid OTP \/ OTP expired \/ Maximum verification attempts reached<\/td>\n<td>Let the user retry, or send a fresh OTP.<\/td>\n<\/tr>\n<tr>\n<td>OTP not found or already verified (HTTP 404)<\/td>\n<td>Already used or replaced. Send a new OTP.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h2>Full copy-paste example: fast2sms.js<\/h2>\n<pre><code class=\"language-javascript\">\/\/ fast2sms.js - Node.js 18+, no dependencies\nconst BASE_URL = \"https:\/\/www.fast2sms.com\";\n\nexport class Fast2SMS {\n  constructor(apiKey = process.env.FAST2SMS_API_KEY) {\n    if (&#33;apiKey) throw new Error(\"FAST2SMS_API_KEY is not set\");\n    this.apiKey = apiKey;\n  }\n\n  async #call(method, path, body) {\n    let res;\n    try {\n      res = await fetch(BASE_URL + path, {\n        method,\n        headers: {\n          authorization: this.apiKey,\n          \"Content-Type\": \"application\/json\",\n          Accept: \"application\/json\",\n        },\n        body: body ? JSON.stringify(body) : undefined,\n        signal: AbortSignal.timeout(15000),\n      });\n    } catch (err) {\n      return { ok: false, http: 0, message: `Network error: ${err.message}`, raw: null };\n    }\n    let data;\n    try {\n      data = await res.json();\n    } catch {\n      return { ok: false, http: res.status, message: \"Non-JSON response\", raw: null };\n    }\n    const msg = Array.isArray(data.message) ? data.message.join(\" \") : data.message ?? \"\";\n    return {\n      ok: res.ok &amp;&amp; (data.return === true || data.success === true),\n      http: res.status,\n      statusCode: data.status_code ?? null,\n      requestId: data.request_id ?? null,\n      message: msg,\n      raw: data,\n    };\n  }\n\n  sendDlt(senderId, messageId, variables, numbers, extra = {}) {\n    return this.#call(\"POST\", \"\/dev\/bulkV2\", {\n      route: \"dlt\",\n      sender_id: senderId,\n      message: String(messageId),\n      variables_values: variables.join(\"|\"),\n      numbers: numbers.join(\",\"),\n      ...extra,\n    });\n  }\n\n  sendOtp(mobile, otpId, { expiry = 5, length = 6, variables } = {}) {\n    const body = { mobile, otp_id: otpId, otp_expiry: expiry, otp_length: length };\n    if (variables?.length) body.variables_values = variables.join(\"|\");\n    return this.#call(\"POST\", \"\/dev\/otp\/send\", body);\n  }\n\n  verifyOtp(mobile, otp) {\n    return this.#call(\"POST\", \"\/dev\/otp\/verify\", { mobile, otp });\n  }\n\n  resendOtp(mobile) {\n    return this.#call(\"POST\", \"\/dev\/otp\/resend\", { mobile });\n  }\n\n  deliveryReport(requestId) {\n    return this.#call(\"GET\", `\/dev\/dlr\/${encodeURIComponent(requestId)}`);\n  }\n}\n\n\/\/ Usage (in an ES module):\n\/\/ import { Fast2SMS } from \".\/fast2sms.js\";\n\/\/ const f2s = new Fast2SMS();\n\/\/ const sms = await f2s.sendDlt(\"DEMOTR\", 10001, [\"Rahul\", \"DT10458\", \"1240\", \"21 Nov\"], [\"9999999999\"]);\n\/\/ console.log(sms.ok ? sms.requestId : sms.message);\n\/\/ const otp = await f2s.sendOtp(\"9999999999\", \"YOUR_OTP_ID\");\n\/\/ const check = await f2s.verifyOtp(\"9999999999\", \"482913\");\n\/\/ console.log(check.ok ? \"verified\" : check.message);<\/code><\/pre>\n<p>The DLR API replies with <code>success<\/code> rather than <code>return<\/code>, so the class accepts both. A ready Express starter kit with this client, send, verify and resend routes, a mock server and tests is also available from Fast2SMS.<\/p>\n<h2>Common problems and fixes<\/h2>\n<ul>\n<li><strong>fetch is not defined:<\/strong> you are on Node.js 16 or older. Upgrade to 18 or later, or use axios.<\/li>\n<li><strong>The key is undefined:<\/strong> the environment variable is not loaded in that process (PM2, Docker, systemd). Set it in the process config.<\/li>\n<li><strong>req.body is undefined in the webhook:<\/strong> add <code>app.use(express.json())<\/code> before the route, and keep the webhook&#8217;s content type as JSON.<\/li>\n<li><strong>Webhook works in tests but not live:<\/strong> localhost and private URLs are refused. Use a public HTTPS URL.<\/li>\n<li><strong>Two SMS for one order:<\/strong> a retry library or a queue retry resent after a timeout. Turn retries off for send calls.<\/li>\n<\/ul>\n<section class=\"f2s-faq\">\n<h2>Frequently asked questions<\/h2>\n<h3>Is there an npm package for Fast2SMS?<\/h3>\n<p>You do not need one. The API is plain HTTPS with JSON. The class above uses only built-in <code>fetch<\/code>.<\/p>\n<h3>Can I call the Fast2SMS API from the browser or React?<\/h3>\n<p>No. The <a href=\"\/help\/api-key-find-reset\/\">API key<\/a> would be visible to anyone. Call your own Node.js backend from the browser, and let the backend call Fast2SMS.<\/p>\n<h3>Does it work with Next.js API routes or serverless functions?<\/h3>\n<p>Yes, as long as the code runs on the server side and the key is a server environment variable. If you turn on API Security, remember that serverless IPs can change.<\/p>\n<h3>How do I send to many numbers?<\/h3>\n<p>Join them with commas in <code>numbers<\/code>. Invalid numbers are skipped and not charged.<\/p>\n<h3>Can I generate the OTP myself?<\/h3>\n<p>Yes. Pass <code>otp<\/code> to Send OTP (up to 10 characters) and Fast2SMS still verifies it. Or send your own DLT OTP template with <code>route=dlt<\/code> and check the code in your app.<\/p>\n<h3>Is verify charged?<\/h3>\n<p>No. Send and resend are charged; verify is not.<\/p>\n<\/section>\n<aside class=\"f2s-cta\" aria-label=\"Get started with Fast2SMS\"><div class=\"f2s-cta__copy\"><strong class=\"f2s-cta__title\">Add SMS and OTP to your Node.js app<\/strong><p>Sign up, set up your DLT or Smart OTP template and use the module above in Express, Next.js or NestJS.<\/p><\/div><div class=\"f2s-cta__actions\"><a class=\"f2s-cta__btn f2s-cta__btn--primary\" href=\"https:\/\/www.fast2sms.com\/\"><span>Sign up free<\/span> <span class=\"f2sh-btn__arrow\" aria-hidden=\"true\">&rarr;<\/span><\/a><a class=\"f2s-cta__btn f2s-cta__btn--ghost\" href=\"https:\/\/www.fast2sms.com\/meet\/\" target=\"_blank\" rel=\"noopener\">Book a free meeting<\/a><\/div><\/aside>\n<h2>Related guides<\/h2>\n<ul>\n<li><a href=\"\/help\/dlt-sms-api-guide\/\">Fast2SMS DLT SMS API: send SMS with your DLT template<\/a><\/li>\n<li><a href=\"\/help\/smart-otp-send-otp-api\/\">Fast2SMS Send OTP API: parameters and code examples<\/a><\/li>\n<li><a href=\"\/help\/smart-otp-verify-otp-api\/\">Fast2SMS Verify OTP API: how verification works<\/a><\/li>\n<li><a href=\"\/help\/fast2sms-webhooks-setup-delivery-reports\/\">Webhooks in Fast2SMS: get delivery reports on your own URL<\/a><\/li>\n<li><a href=\"\/help\/api-security-ip-whitelist\/\">Restrict the Fast2SMS API to your server IP<\/a><\/li>\n<li><a href=\"https:\/\/www.fast2sms.com\/otp-sms\">Fast2SMS OTP SMS<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>This guide shows how to send SMS and OTP from Node.js with the Fast2SMS API. It uses the fetch that is built into Node.js 18 and later, so you install nothing extra (an axios version is included too). You will send a DLT SMS, send and verify an OTP with Smart OTP, get delivery reports [&hellip;]<\/p>\n","protected":false},"featured_media":18044,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,13,5],"tags":[],"class_list":["post-18050","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-api","category-bulk-sms","category-otp"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Send SMS and OTP in Node.js: SMS API Code | Fast2SMS<\/title>\n<meta name=\"description\" content=\"Send DLT SMS and OTP from Node.js with the Fast2SMS API using fetch or axios. Smart OTP verify, delivery report, Express webhook and error handling.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.fast2sms.com\/help\/nodejs-sms-api\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Send SMS and OTP in Node.js: SMS API Code | Fast2SMS\" \/>\n<meta property=\"og:description\" content=\"Send DLT SMS and OTP from Node.js with the Fast2SMS API using fetch or axios. Smart OTP verify, delivery report, Express webhook and error handling.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.fast2sms.com\/help\/nodejs-sms-api\/\" \/>\n<meta property=\"og:site_name\" content=\"Fast2SMS\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Fast2SMS\/\" \/>\n<meta property=\"article:published_time\" content=\"2026-11-18T18:15:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-18T19:20:35+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/api-key-hd-11-scaled.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"2560\" \/>\n\t<meta property=\"og:image:height\" content=\"1600\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@fast2sms\" \/>\n<meta name=\"twitter:site\" content=\"@fast2sms\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/nodejs-sms-api\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/nodejs-sms-api\\\/\"},\"author\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/#organization\"},\"headline\":\"Send SMS and OTP in Node.js with Fast2SMS API (fetch \\\/ axios)\",\"datePublished\":\"2026-11-18T18:15:47+00:00\",\"dateModified\":\"2026-11-18T19:20:35+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/nodejs-sms-api\\\/\"},\"wordCount\":1309,\"publisher\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/nodejs-sms-api\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/api-key-hd-11-scaled.webp\",\"articleSection\":[\"API\",\"Bulk SMS\",\"OTP\"],\"inLanguage\":\"en-IN\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/nodejs-sms-api\\\/\",\"url\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/nodejs-sms-api\\\/\",\"name\":\"Send SMS and OTP in Node.js: SMS API Code | Fast2SMS\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/nodejs-sms-api\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/nodejs-sms-api\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/api-key-hd-11-scaled.webp\",\"datePublished\":\"2026-11-18T18:15:47+00:00\",\"dateModified\":\"2026-11-18T19:20:35+00:00\",\"description\":\"Send DLT SMS and OTP from Node.js with the Fast2SMS API using fetch or axios. Smart OTP verify, delivery report, Express webhook and error handling.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/nodejs-sms-api\\\/#breadcrumb\"},\"inLanguage\":\"en-IN\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/nodejs-sms-api\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-IN\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/nodejs-sms-api\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/api-key-hd-11-scaled.webp\",\"contentUrl\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/api-key-hd-11-scaled.webp\",\"width\":2560,\"height\":1600,\"caption\":\"API Key page with masked Authorization Key, View and Reset buttons, API Access and Quick API Access switches\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/nodejs-sms-api\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"API\",\"item\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/api\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Send SMS and OTP in Node.js with Fast2SMS API (fetch \\\/ axios)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/#website\",\"url\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/\",\"name\":\"Fast2SMS\",\"description\":\"Help\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/#organization\"},\"inLanguage\":\"en-IN\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/#organization\",\"name\":\"Fast2SMS\",\"url\":\"https:\\\/\\\/www.fast2sms.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/#logo\",\"url\":\"https:\\\/\\\/www.fast2sms.com\\\/Fast2SMS.png\",\"contentUrl\":\"https:\\\/\\\/www.fast2sms.com\\\/Fast2SMS.png\",\"caption\":\"Fast2SMS\"},\"image\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/#logo\"},\"email\":\"support@fast2sms.com\",\"telephone\":\"+91-6262778822\",\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/Fast2SMS\",\"https:\\\/\\\/www.instagram.com\\\/fast2sms\",\"https:\\\/\\\/x.com\\\/fast2sms\",\"https:\\\/\\\/www.youtube.com\\\/Fast2SMSofficial\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/fast2sms\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Send SMS and OTP in Node.js: SMS API Code | Fast2SMS","description":"Send DLT SMS and OTP from Node.js with the Fast2SMS API using fetch or axios. Smart OTP verify, delivery report, Express webhook and error handling.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.fast2sms.com\/help\/nodejs-sms-api\/","og_locale":"en_US","og_type":"article","og_title":"Send SMS and OTP in Node.js: SMS API Code | Fast2SMS","og_description":"Send DLT SMS and OTP from Node.js with the Fast2SMS API using fetch or axios. Smart OTP verify, delivery report, Express webhook and error handling.","og_url":"https:\/\/www.fast2sms.com\/help\/nodejs-sms-api\/","og_site_name":"Fast2SMS","article_publisher":"https:\/\/www.facebook.com\/Fast2SMS\/","article_published_time":"2026-11-18T18:15:47+00:00","article_modified_time":"2026-11-18T19:20:35+00:00","og_image":[{"width":2560,"height":1600,"url":"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/api-key-hd-11-scaled.webp","type":"image\/webp"}],"twitter_card":"summary_large_image","twitter_creator":"@fast2sms","twitter_site":"@fast2sms","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.fast2sms.com\/help\/nodejs-sms-api\/#article","isPartOf":{"@id":"https:\/\/www.fast2sms.com\/help\/nodejs-sms-api\/"},"author":{"@id":"https:\/\/www.fast2sms.com\/#organization"},"headline":"Send SMS and OTP in Node.js with Fast2SMS API (fetch \/ axios)","datePublished":"2026-11-18T18:15:47+00:00","dateModified":"2026-11-18T19:20:35+00:00","mainEntityOfPage":{"@id":"https:\/\/www.fast2sms.com\/help\/nodejs-sms-api\/"},"wordCount":1309,"publisher":{"@id":"https:\/\/www.fast2sms.com\/#organization"},"image":{"@id":"https:\/\/www.fast2sms.com\/help\/nodejs-sms-api\/#primaryimage"},"thumbnailUrl":"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/api-key-hd-11-scaled.webp","articleSection":["API","Bulk SMS","OTP"],"inLanguage":"en-IN"},{"@type":"WebPage","@id":"https:\/\/www.fast2sms.com\/help\/nodejs-sms-api\/","url":"https:\/\/www.fast2sms.com\/help\/nodejs-sms-api\/","name":"Send SMS and OTP in Node.js: SMS API Code | Fast2SMS","isPartOf":{"@id":"https:\/\/www.fast2sms.com\/help\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.fast2sms.com\/help\/nodejs-sms-api\/#primaryimage"},"image":{"@id":"https:\/\/www.fast2sms.com\/help\/nodejs-sms-api\/#primaryimage"},"thumbnailUrl":"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/api-key-hd-11-scaled.webp","datePublished":"2026-11-18T18:15:47+00:00","dateModified":"2026-11-18T19:20:35+00:00","description":"Send DLT SMS and OTP from Node.js with the Fast2SMS API using fetch or axios. Smart OTP verify, delivery report, Express webhook and error handling.","breadcrumb":{"@id":"https:\/\/www.fast2sms.com\/help\/nodejs-sms-api\/#breadcrumb"},"inLanguage":"en-IN","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.fast2sms.com\/help\/nodejs-sms-api\/"]}]},{"@type":"ImageObject","inLanguage":"en-IN","@id":"https:\/\/www.fast2sms.com\/help\/nodejs-sms-api\/#primaryimage","url":"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/api-key-hd-11-scaled.webp","contentUrl":"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/api-key-hd-11-scaled.webp","width":2560,"height":1600,"caption":"API Key page with masked Authorization Key, View and Reset buttons, API Access and Quick API Access switches"},{"@type":"BreadcrumbList","@id":"https:\/\/www.fast2sms.com\/help\/nodejs-sms-api\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.fast2sms.com\/help\/"},{"@type":"ListItem","position":2,"name":"API","item":"https:\/\/www.fast2sms.com\/help\/api\/"},{"@type":"ListItem","position":3,"name":"Send SMS and OTP in Node.js with Fast2SMS API (fetch \/ axios)"}]},{"@type":"WebSite","@id":"https:\/\/www.fast2sms.com\/help\/#website","url":"https:\/\/www.fast2sms.com\/help\/","name":"Fast2SMS","description":"Help","publisher":{"@id":"https:\/\/www.fast2sms.com\/#organization"},"inLanguage":"en-IN"},{"@type":"Organization","@id":"https:\/\/www.fast2sms.com\/#organization","name":"Fast2SMS","url":"https:\/\/www.fast2sms.com\/","logo":{"@type":"ImageObject","@id":"https:\/\/www.fast2sms.com\/#logo","url":"https:\/\/www.fast2sms.com\/Fast2SMS.png","contentUrl":"https:\/\/www.fast2sms.com\/Fast2SMS.png","caption":"Fast2SMS"},"image":{"@id":"https:\/\/www.fast2sms.com\/#logo"},"email":"support@fast2sms.com","telephone":"+91-6262778822","sameAs":["https:\/\/www.facebook.com\/Fast2SMS","https:\/\/www.instagram.com\/fast2sms","https:\/\/x.com\/fast2sms","https:\/\/www.youtube.com\/Fast2SMSofficial","https:\/\/www.linkedin.com\/company\/fast2sms"]}]}},"_links":{"self":[{"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/posts\/18050","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/comments?post=18050"}],"version-history":[{"count":1,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/posts\/18050\/revisions"}],"predecessor-version":[{"id":19357,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/posts\/18050\/revisions\/19357"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/media\/18044"}],"wp:attachment":[{"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/media?parent=18050"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/categories?post=18050"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/tags?post=18050"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}