{"id":18747,"date":"2026-11-19T00:12:05","date_gmt":"2026-11-18T18:42:05","guid":{"rendered":"https:\/\/www.fast2sms.com\/help\/otp-login-nodejs-express-fast2sms\/"},"modified":"2026-11-19T00:51:14","modified_gmt":"2026-11-18T19:21:14","slug":"otp-login-nodejs-express-fast2sms","status":"publish","type":"post","link":"https:\/\/www.fast2sms.com\/help\/otp-login-nodejs-express-fast2sms\/","title":{"rendered":"Node.js Express OTP login with Fast2SMS Smart OTP (starter kit)"},"content":{"rendered":"<p>This guide shows you how to build a Node.js Express OTP login page with Fast2SMS Smart OTP. Our starter kit is a small Express app with sessions and CSRF tokens, plus a Fast2SMS client with no dependencies that uses Node&#8217;s built-in <code>fetch<\/code>. Users type their mobile number, get a code by SMS or WhatsApp and log in.<\/p>\n<aside class=\"f2s-cta\" aria-label=\"Get started with Fast2SMS\"><div class=\"f2s-cta__copy\"><strong class=\"f2s-cta__title\">Add OTP login to your Node.js Express app<\/strong><p>Create a Smart OTP template, copy your OTP ID and start sending codes on SMS and WhatsApp.<\/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>What you build<\/h2>\n<p>A login page that works like this:<\/p>\n<ol>\n<li>The user types a mobile number and clicks <strong>Send OTP<\/strong>. Fast2SMS creates the code and sends it.<\/li>\n<li>The user types the code and clicks <strong>Verify<\/strong>. Fast2SMS checks it, and your app logs the user in.<\/li>\n<li>A <strong>Resend code<\/strong> button works after a short wait (30 seconds by default).<\/li>\n<\/ol>\n<p>The kit uses <strong>Smart OTP<\/strong>, our recommended way to send OTPs. An OTP template sends on SMS or WhatsApp, with optional fallback to the other channel, on a priority route. Fast2SMS creates, stores and checks the code, so your app does not keep any OTP itself.<\/p>\n<p class=\"f2s-kit-wrap\"><a class=\"f2s-kit\" href=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/fast2sms-smart-otp-node-express.zip\" download><svg class=\"f2s-kit__icon\" width=\"28\" height=\"28\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path fill=\"#7F56D9\" d=\"M6 2h8l6 6v12a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2z\"\/><path fill=\"#FFFFFF\" d=\"M14 2v6h6\"\/><path fill=\"#FFFFFF\" d=\"M9 6h2v2H9zm2 2h2v2h-2zM9 10h2v2H9zm2 2h2v2h-2zm-2 2h4v4H9z\"\/><rect x=\"10\" y=\"15.4\" width=\"2\" height=\"1.6\" fill=\"#7F56D9\"\/><\/svg><span class=\"f2s-kit__text\"><strong>Download the ready-made starter kit (zip)<\/strong><span class=\"f2s-kit__meta\">fast2sms-smart-otp-node-express.zip &middot; 32 KB<\/span><\/span><span class=\"f2s-kit__btn\">Download .zip<\/span><\/a><\/p>\n<div class=\"f2s-note\">We tested this kit with Node.js 24.18.0, Express 5.3.0 and express-session 1.19.0 against a local copy of the Fast2SMS API (a mock server, so no real SMS was sent): all 23 client tests (<code>npm test<\/code>) and the full 16-step browser test passed. The code uses only features that exist in Node.js 18.<\/div>\n<h2>Before you start<\/h2>\n<ul>\n<li>A Fast2SMS account with wallet balance. Every OTP you send is charged.<\/li>\n<li>For SMS OTP: an approved DLT entity, sender ID and OTP content template in <strong>DLT Manager<\/strong>. For WhatsApp OTP: a connected WhatsApp number with an approved authentication (or utility) template.<\/li>\n<li>Node.js 18 or newer (it has <code>fetch<\/code> built in) and npm.<\/li>\n<\/ul>\n<h2>Set up Node.js Express OTP login in 5 steps<\/h2>\n<ol class=\"f2s-steps\">\n<li>\n<h3>Create a Smart OTP template<\/h3>\n<p>In the panel, open <strong>Smart OTP<\/strong> &gt; <strong>OTP Template List<\/strong> and click <strong>Add OTP Template<\/strong>. On the <strong>SMS Channel<\/strong> tab, pick your entity, sender and approved DLT OTP template, then click the variable button that holds the code and click <strong>Assign OTP Template<\/strong>. For WhatsApp, use the <strong>WhatsApp Channel<\/strong> tab. You can also tick <strong>SET FALLBACK TEMPLATE<\/strong> to add the other channel as a fallback.<\/p>\n<figure class=\"f2s-shot\"><img src=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/smart-otp-add-sms-filled-hd-8-scaled.webp\" width=\"1440\" height=\"900\" loading=\"lazy\" decoding=\"async\" alt=\"Add OTP Template window on the SMS Channel tab with entity, sender and DLT template selected and the variable buttons below the preview\"><figcaption>Pick the entity, sender and DLT template, then choose which variable holds the OTP.<\/figcaption><\/figure>\n<\/li>\n<li>\n<h3>Copy the OTP ID<\/h3>\n<p>Your new template shows as a card in the <strong>OTP Template List<\/strong>. Copy its <strong>OTP ID<\/strong> with the copy icon. It is 10 characters long, for example <code>a1b2c3d4e5<\/code>.<\/p>\n<figure class=\"f2s-shot\"><img src=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/smart-otp-template-list-hd-24-scaled.webp\" width=\"1440\" height=\"900\" loading=\"lazy\" decoding=\"async\" alt=\"Smart OTP Template list with WhatsApp and SMS template cards, each showing its OTP ID with a copy icon\"><figcaption>Each card shows the OTP ID you put in your .env file.<\/figcaption><\/figure>\n<\/li>\n<li>\n<h3>Copy your API key<\/h3>\n<p>In the left menu under <strong>Utility<\/strong>, click <strong>API Key<\/strong>. Click <strong>View<\/strong> to see the full <strong>Authorization Key<\/strong> (the panel asks for an OTP sent to your registered mobile first) and copy it. Check that <strong>API Access<\/strong> is switched on.<\/p>\n<figure class=\"f2s-shot\"><img src=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/api-key-hd-27-scaled.webp\" width=\"1440\" height=\"900\" loading=\"lazy\" decoding=\"async\" alt=\"API Key page with the masked Authorization Key, View and Reset buttons and the API Access switch turned on\"><figcaption>Copy the Authorization Key. API Access must be on.<\/figcaption><\/figure>\n<\/li>\n<li>\n<h3>Put the API key and OTP ID in .env<\/h3>\n<p>In the unzipped kit, run <code>npm install<\/code>. Copy <code>.env.example<\/code> to <code>.env<\/code> and fill it in. <code>SESSION_SECRET<\/code> signs the session cookie, so use a long random value:<\/p>\n<pre><code class=\"language-bash\">FAST2SMS_API_KEY=YOUR_API_KEY\nFAST2SMS_OTP_ID=a1b2c3d4e5\nOTP_RESEND_WAIT_SECONDS=30\nSESSION_SECRET=a-long-random-string\nPORT=3000<\/code><\/pre>\n<p>Never commit <code>.env<\/code> to git; make sure your <code>.gitignore<\/code> lists it.<\/p>\n<\/li>\n<li>\n<h3>Run it and log in<\/h3>\n<p>Start the app:<\/p>\n<pre><code class=\"language-bash\">npm start<\/code><\/pre>\n<p>Open <code>http:\/\/127.0.0.1:3000<\/code>, type your own mobile number and click <strong>Send OTP<\/strong>, then type the code and click <strong>Verify<\/strong>.<\/p>\n<\/li>\n<\/ol>\n<h2>How send, verify and resend work in the Node.js Express kit<\/h2>\n<div class=\"f2s-facts\">\n<table>\n<thead>\n<tr>\n<th>Step<\/th>\n<th>Your app calls<\/th>\n<th>Fast2SMS endpoint<\/th>\n<th>Charged?<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Send<\/td>\n<td><code>await client.send(mobile, otpId)<\/code><\/td>\n<td><code>POST \/dev\/otp\/send<\/code><\/td>\n<td>Yes<\/td>\n<\/tr>\n<tr>\n<td>Verify<\/td>\n<td><code>await client.verify(mobile, code)<\/code><\/td>\n<td><code>POST \/dev\/otp\/verify<\/code><\/td>\n<td>No<\/td>\n<\/tr>\n<tr>\n<td>Resend<\/td>\n<td><code>await client.resendOrSend(mobile, otpId)<\/code><\/td>\n<td><code>POST \/dev\/otp\/resend<\/code>, falls back to send<\/td>\n<td>Yes<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>The client is <code>src\/fast2smsSmartOtp.js<\/code> with no dependencies. Copy it into your own Express, Fastify or Next.js API code. The routes are in <code>app.js<\/code> and the HTML in <code>views.js<\/code>.<\/p>\n<h3>Send<\/h3>\n<p>The kit first cleans the number, so <code>+91 98765-43210<\/code> becomes <code>9876543210<\/code>. Anything that is not a 10-digit Indian mobile starting with 6 to 9 is refused before any API call, so it costs nothing. Then it sends the mobile and your OTP ID. Fast2SMS makes a 6-digit code that is valid for 15 minutes, unless you pass <code>otp_length<\/code> (4 to 10) or <code>otp_expiry<\/code> (1 to 10080 minutes).<\/p>\n<p>&#8220;OTP sent successfully&#8221; means Fast2SMS accepted the request. It does not mean the phone has received it. Delivery shows in <strong>Smart OTP<\/strong> &gt; <strong>Delivery Report<\/strong> and in the OTP webhook.<\/p>\n<h3>Verify<\/h3>\n<p>Verify needs only the mobile and the code the user typed, no OTP ID. Fast2SMS checks the latest unverified code for that mobile. Sending a new OTP cancels the older codes, so only the newest one works. The result is one of <code>verified<\/code>, <code>invalid<\/code> (wrong code, one try used), <code>expired<\/code>, <code>max_attempts<\/code> or <code>not_found<\/code>.<\/p>\n<p>This is the verify step from <code>app.js<\/code>. On success it regenerates the session:<\/p>\n<pre><code class=\"language-javascript\">const r = await client.verify(s.pendingMobile, otp);\nif (r.ok) {\n  \/\/ Logged in. A new session id stops session fixation.\n  const mobile = s.pendingMobile;\n  await regenerate(req);\n  req.session.userMobile = mobile;\n} else {\n  s.needNewCode = ['expired', 'max_attempts', 'not_found'].includes(r.reason);\n  flash('error', VERIFY_MESSAGES[r.reason] || 'Could not check the code: ' + r.message);\n}<\/code><\/pre>\n<h3>Resend<\/h3>\n<p>Resend sends the same code again and is charged like a new send. It works only within 10 minutes of the last send, and Fast2SMS allows at most 5 sends to one number in those 10 minutes, counting the first. So a user gets up to 4 resends. When there is nothing to resend (never sent, already verified, or the 10 minutes are over), the kit sends a new code instead:<\/p>\n<pre><code class=\"language-javascript\">async resendOrSend(mobile, otpId, options = {}) {\n  let r = await this.resend(mobile);\n  if (['no_previous', 'already_verified', 'window_expired'].includes(r.reason)) {\n    r = await this.send(mobile, otpId, options);\n    r.sentNew = true;\n  }\n  return r;\n}<\/code><\/pre>\n<p>The <a href=\"\/help\/api-key-find-reset\/\">API key<\/a> goes in the <code>authorization<\/code> header as the bare key. Do not add <code>Bearer <\/code> in front: the OTP API refuses it.<\/p>\n<pre><code class=\"language-javascript\">authorization: this.apiKey, \/\/ bare key, no \"Bearer \", never in the URL<\/code><\/pre>\n<p>The kit never retries a send or resend on its own, because a retry after a timeout could send, and charge, twice. It retries once, after 1 second, only when the connection could not be opened or Fast2SMS answered 502, 503 or 504 with an error page.<\/p>\n<aside class=\"f2s-cta\" aria-label=\"Get started with Fast2SMS\"><div class=\"f2s-cta__copy\"><strong class=\"f2s-cta__title\">Get your OTP ID in a few minutes<\/strong><p>Create a Smart OTP template on SMS or WhatsApp and plug it into the Node.js Express starter kit.<\/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>Security notes<\/h2>\n<h3>Never expose the API key<\/h3>\n<ul>\n<li>Call Fast2SMS only from your server. Never put the API key in JavaScript, a mobile app or a page the browser can download.<\/li>\n<li>Keep the key in <code>.env<\/code> or environment variables, out of git. If it ever leaks, click <strong>Reset<\/strong> on the <strong>API Key<\/strong> page; the old key stops working.<\/li>\n<li>Turn on <strong>API Security<\/strong> and whitelist your server&#8217;s public IP, so a stolen key does not work from anywhere else.<\/li>\n<li>The kit never writes the OTP or the full key to its logs. Mobiles are logged as <code>98xxxxxx10<\/code>.<\/li>\n<\/ul>\n<h3>Rate limits<\/h3>\n<p>Every send costs money, so limit who can press <strong>Send OTP<\/strong>. There are three layers:<\/p>\n<ul>\n<li><strong>The kit&#8217;s wait:<\/strong> the Resend button works only after <code>OTP_RESEND_WAIT_SECONDS<\/code> (30 by default). Clicks before that make no API call.<\/li>\n<li><strong>Fast2SMS limits:<\/strong> the <strong>SMS Resend \/ Time Limit<\/strong> in <strong>OTP Settings<\/strong> (10 seconds if not set, 0 to 3600) and the fixed cap of 5 sends per number in 10 minutes.<\/li>\n<li><strong>Your own limit:<\/strong> add a limit per IP address or a CAPTCHA on the Send button. Bots that try many different numbers are not stopped by per-number limits.<\/li>\n<\/ul>\n<p>The demo uses express-session&#8217;s memory store, which loses sessions on restart and does not work with more than one process. Use a Redis or database session store in production, and set <code>cookie.secure: true<\/code> once you are on HTTPS.<\/p>\n<p>Each call has a 15-second limit. Node&#8217;s <code>fetch<\/code> has no separate connect timeout, so a connect can take up to 10 seconds of that.<\/p>\n<h3>Verify attempts<\/h3>\n<p>Set <strong>Max Verify OTP Limit (Per SMS)<\/strong> in <strong>Smart OTP<\/strong> &gt; <strong>OTP Settings<\/strong>. It can be 1 to 100 and is 10 if you never set it; 3 to 5 suits most login pages. When the limit is reached, the code stops working and the kit shows &#8220;Too many wrong tries&#8221; with a <strong>Send new code<\/strong> button.<\/p>\n<figure class=\"f2s-shot\"><img src=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/smart-otp-settings-hd-17-scaled.webp\" width=\"1440\" height=\"900\" loading=\"lazy\" decoding=\"async\" alt=\"OTP Settings page with Max Verify OTP Limit set to 5 and SMS Resend Time Limit set to 30 seconds\"><figcaption>Five tries per code and a 30-second wait between sends.<\/figcaption><\/figure>\n<div class=\"f2s-note f2s-note--warn\">After &#8220;Too many wrong tries&#8221; or &#8220;This code has expired&#8221;, give the user a fresh code with <code>await client.send(mobile, otpId)<\/code>. Do not re-send the old code. In the kit, the <strong>Send new code<\/strong> button calls <code>await client.resendOrSend(mobile, otpId)<\/code>; for a stricter setup, change it to call send when the last verify ended in <code>max_attempts<\/code>.<\/div>\n<p>Every send and every resend is charged at your OTP rate; verify is free. A fallback message on the second channel is also charged. See the current rates on the <a href=\"https:\/\/www.fast2sms.com\/otp-sms\">OTP SMS page<\/a>.<\/p>\n<div class=\"f2s-note f2s-volume\"><p><strong>Sending in bulk?<\/strong> For high OTP volumes our team offers discounted rates. <a href=\"https:\/\/www.fast2sms.com\/meet\/\" target=\"_blank\" rel=\"noopener\">Talk to our team<\/a> or see <a href=\"https:\/\/www.fast2sms.com\/bulk-sms-pricing\">OTP pricing<\/a>.<\/p><\/div>\n<p>Use HTTPS on the live site. After a correct code the kit starts a new session (or sign-in cookie), which stops session fixation, and every form carries a CSRF token.<\/p>\n<h2>OTP over DLT SMS: the second Node.js Express kit<\/h2>\n<p>Smart OTP is the easier choice. If you would rather send OTPs through your own approved DLT OTP template with the DLT SMS API, use our &#8220;OTP over DLT&#8221; kit for the same stack. It has the same login page, but the work is split differently:<\/p>\n<ul>\n<li><strong>Your app makes the code<\/strong> with a secure random generator and keeps only an HMAC-SHA256 hash of it, with the expiry time and a try counter. The code is never stored, logged or shown.<\/li>\n<li><strong>Fast2SMS only delivers the SMS.<\/strong> In <code>dlt<\/code> mode the kit calls <code>\/dev\/bulkV2<\/code> with <code>route=dlt<\/code>, your sender ID and the template&#8217;s Message ID. In <code>dlt_manual<\/code> mode it calls <code>\/dev\/custom<\/code> with <code>route=dlt_manual<\/code>, your Entity ID, the 19-digit DLT Template ID and the full text.<\/li>\n<li><strong>Verify happens in your app<\/strong> with a constant-time compare. No API call, no charge.<\/li>\n<li><strong>Resend sends a new code<\/strong> and the old one stops working.<\/li>\n<\/ul>\n<p>The two calls are <code>await otp.sendOtp(mobile)<\/code> and <code>await otp.verifyOtp(mobile, code)<\/code> in <code>src\/fast2smsDltOtp.js<\/code>. These are the DLT settings in its <code>.env<\/code>, next to the API key and an <code>OTP_HASH_SECRET<\/code> (a long random string; the app will not start without it):<\/p>\n<pre><code class=\"language-bash\"># How to send: dlt (DLT SMS, default) or dlt_manual (DLT Manual).\nOTP_SEND_MODE=dlt\n\n# Your approved DLT sender ID, exactly as in DLT Manager (case matters).\nFAST2SMS_SENDER_ID=FSTSMS\n\n# DLT SMS: the \"Message ID\" from the template card in DLT Manager. NOT the 19-digit DLT Template ID.\nFAST2SMS_DLT_MESSAGE_ID=111111\nFAST2SMS_DLT_VARIABLES={otp}\n\n# DLT Manual: the full approved DLT text, with {otp} where the code goes.\nFAST2SMS_DLT_MANUAL_TEXT=Your OTP is {otp} for Login. -Demo\nFAST2SMS_DLT_ENTITY_ID=1101234567890123456\nFAST2SMS_DLT_TEMPLATE_ID=1107123456789012345<\/code><\/pre>\n<div class=\"f2s-facts\">\n<table>\n<thead>\n<tr>\n<th>Rule<\/th>\n<th>Default<\/th>\n<th>Setting<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Code length<\/td>\n<td>6 digits (4 to 6 allowed)<\/td>\n<td><code>OTP_LENGTH<\/code><\/td>\n<\/tr>\n<tr>\n<td>Code expires after<\/td>\n<td>5 minutes<\/td>\n<td><code>OTP_EXPIRY_MINUTES<\/code><\/td>\n<\/tr>\n<tr>\n<td>Wrong tries per code<\/td>\n<td>5, then the code is deleted<\/td>\n<td><code>OTP_MAX_ATTEMPTS<\/code><\/td>\n<\/tr>\n<tr>\n<td>Wait between sends to one number<\/td>\n<td>30 seconds<\/td>\n<td><code>OTP_RESEND_WAIT_SECONDS<\/code><\/td>\n<\/tr>\n<tr>\n<td>Sends per number per hour<\/td>\n<td>5<\/td>\n<td><code>OTP_MAX_SENDS_PER_HOUR<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div class=\"f2s-note f2s-note--warn\">Use the <strong>Message ID<\/strong> from the template card in <strong>DLT Manager<\/strong>, not the 19-digit DLT Template ID. The sender ID is case-sensitive. In <a href=\"\/help\/dlt-manual-api-guide\/\">DLT Manual<\/a> mode, Fast2SMS does not check your text against the template: if it does not match exactly, the SMS fails at the operator and is not refunded.<\/div>\n<p>OTP records live in memory (<code>MemoryStore<\/code>). Run one process only, or write a small store for Redis or your database. This kit was run with Node.js 24.18.0 against the mock server in both modes: 20 of 20 tests (<code>npm test<\/code>) and the 11-step browser test passed each time.<\/p>\n<p class=\"f2s-kit-wrap\"><a class=\"f2s-kit\" href=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/fast2sms-otp-dlt-node-express.zip\" download><svg class=\"f2s-kit__icon\" width=\"28\" height=\"28\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path fill=\"#7F56D9\" d=\"M6 2h8l6 6v12a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2z\"\/><path fill=\"#FFFFFF\" d=\"M14 2v6h6\"\/><path fill=\"#FFFFFF\" d=\"M9 6h2v2H9zm2 2h2v2h-2zM9 10h2v2H9zm2 2h2v2h-2zm-2 2h4v4H9z\"\/><rect x=\"10\" y=\"15.4\" width=\"2\" height=\"1.6\" fill=\"#7F56D9\"\/><\/svg><span class=\"f2s-kit__text\"><strong>Download the OTP over DLT starter kit (zip)<\/strong><span class=\"f2s-kit__meta\">fast2sms-otp-dlt-node-express.zip &middot; 35 KB<\/span><\/span><span class=\"f2s-kit__btn\">Download .zip<\/span><\/a><\/p>\n<h2>Common problems and fixes<\/h2>\n<div class=\"f2s-facts\">\n<table>\n<thead>\n<tr>\n<th>What you see<\/th>\n<th>Why<\/th>\n<th>Fix<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>&#8220;SMS login is not set up correctly&#8221; and <code>Invalid authorization key<\/code> in the log<\/td>\n<td>Wrong key, or <code>Bearer <\/code> in front of it<\/td>\n<td>Copy the key again from <strong>API Key<\/strong> and send it bare.<\/td>\n<\/tr>\n<tr>\n<td><code>Authorization Key Disabled<\/code> (413) in the log<\/td>\n<td>API Access is off<\/td>\n<td>Switch on <strong>API Access<\/strong> on the API Key page.<\/td>\n<\/tr>\n<tr>\n<td><code>IP is blacklisted<\/code> (414) in the log<\/td>\n<td><a href=\"\/help\/api-security-ip-whitelist\/\">API Security<\/a> is on and your server IP is not listed<\/td>\n<td>Add the server&#8217;s public IP in <strong>API Security<\/strong>.<\/td>\n<\/tr>\n<tr>\n<td>&#8220;Could not send the code: Invalid OTP ID&#8221;<\/td>\n<td>The OTP ID is wrong, deleted or from another account<\/td>\n<td>Copy it from <strong>OTP Template List<\/strong>, in the same account as the key.<\/td>\n<\/tr>\n<tr>\n<td>&#8220;Please wait N seconds before asking for a new code.&#8221;<\/td>\n<td>Fast2SMS cooldown for this number<\/td>\n<td>Wait, or change the time in <strong>OTP Settings<\/strong>.<\/td>\n<\/tr>\n<tr>\n<td>&#8220;Could not send the code: Insufficient wallet balance&#8221;<\/td>\n<td>Low balance<\/td>\n<td>Recharge with <strong>Add Amount<\/strong>.<\/td>\n<\/tr>\n<tr>\n<td>&#8220;Maximum resend limit (5 times) reached&#8221;<\/td>\n<td>5 sends to this number in 10 minutes<\/td>\n<td>Wait and try later.<\/td>\n<\/tr>\n<tr>\n<td>&#8220;Could not reach the SMS service.&#8221;<\/td>\n<td>Network problem, or Fast2SMS was busy<\/td>\n<td>Try again in a minute.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h2>Test without sending SMS<\/h2>\n<p>Each kit has a fake Fast2SMS server in its <code>mock<\/code> folder (it needs Python 3). It never sends an SMS, and with it the correct code is always <code>123456<\/code>. Start it, then run the tests in a second terminal:<\/p>\n<pre><code class=\"language-bash\">python mock\/mock_fast2sms.py\nFAST2SMS_BASE_URL=http:\/\/127.0.0.1:4010 npm test<\/code><\/pre>\n<p>To click through the login page with the mock, set <code>FAST2SMS_API_KEY=TEST_KEY_OK<\/code> and <code>FAST2SMS_BASE_URL=http:\/\/127.0.0.1:4010<\/code> in <code>.env<\/code>. Remove <code>FAST2SMS_BASE_URL<\/code> before you go live.<\/p>\n<section class=\"f2s-faq\">\n<h2>Frequently asked questions<\/h2>\n<h3>Can I call the Fast2SMS OTP API from React or the browser?<\/h3>\n<p>No. The API key would be visible to anyone who opens your page. Keep the calls in your Express server and let the browser talk only to your own routes.<\/p>\n<h3>Does the client need axios or any npm package?<\/h3>\n<p>No. <code>src\/fast2smsSmartOtp.js<\/code> uses Node&#8217;s built-in <code>fetch<\/code>. Only the demo app needs Express and express-session.<\/p>\n<h3>Is the starter kit free?<\/h3>\n<p>Yes. The kit is free under the MIT license. You pay only for the OTPs you send from your Fast2SMS wallet.<\/p>\n<h3>Can the same code send the OTP on WhatsApp?<\/h3>\n<p>Yes. The code only knows the OTP ID. If that OTP ID uses a WhatsApp authentication template, or has a WhatsApp fallback, Fast2SMS handles the channel and your code stays the same.<\/p>\n<h3>The page says the code was sent, but no SMS arrived. Why?<\/h3>\n<p>&#8220;OTP sent successfully&#8221; means Fast2SMS accepted the request. Check the status in <strong>Smart OTP<\/strong> &gt; <strong>Delivery Report<\/strong>. If the message failed and you set a fallback, the same OTP goes out once on the other channel.<\/p>\n<h3>How many times can a user resend the OTP?<\/h3>\n<p>Up to 4 times: Fast2SMS allows 5 sends of one OTP ID to a number in 10 minutes, counting the first. The wait between sends comes from your OTP Settings and the kit&#8217;s 30-second Resend wait.<\/p>\n<\/section>\n<aside class=\"f2s-cta\" aria-label=\"Get started with Fast2SMS\"><div class=\"f2s-cta__copy\"><strong class=\"f2s-cta__title\">Start sending OTPs from Node.js Express<\/strong><p>Sign up, create your OTP template and log users in with SMS or WhatsApp codes.<\/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\/smart-otp-setup-guide-fast2sms\/\">Smart OTP in Fast2SMS: set up OTP on SMS and WhatsApp with fallback<\/a><\/li>\n<li><a href=\"\/help\/dlt-manager-entity-sender-template-guide\/\">DLT Manager in Fast2SMS: add Entity ID, Sender ID and templates<\/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=\"https:\/\/www.fast2sms.com\/help\/how-to-get-dlt-template-id-for-otp-and-transactional-sms\/\">How to get a DLT Template ID for OTP and transactional SMS<\/a><\/li>\n<li><a href=\"https:\/\/www.fast2sms.com\/otp-sms\">Fast2SMS OTP SMS<\/a><\/li>\n<li><a href=\"https:\/\/docs.fast2sms.com\">Fast2SMS API documentation<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>This guide shows you how to build a Node.js Express OTP login page with Fast2SMS Smart OTP. Our starter kit is a small Express app with sessions and CSRF tokens, plus a Fast2SMS client with no dependencies that uses Node&#8217;s built-in fetch. Users type their mobile number, get a code by SMS or WhatsApp and [&hellip;]<\/p>\n","protected":false},"featured_media":18735,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,5],"tags":[],"class_list":["post-18747","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-api","category-otp"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Node.js Express OTP Login with Smart OTP | Fast2SMS<\/title>\n<meta name=\"description\" content=\"Build a Node.js Express OTP login page with Fast2SMS Smart OTP. Run the free starter kit in 5 steps; learn send, verify, resend, limits and DLT option.\" \/>\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\/otp-login-nodejs-express-fast2sms\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Node.js Express OTP Login with Smart OTP | Fast2SMS\" \/>\n<meta property=\"og:description\" content=\"Build a Node.js Express OTP login page with Fast2SMS Smart OTP. Run the free starter kit in 5 steps; learn send, verify, resend, limits and DLT option.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.fast2sms.com\/help\/otp-login-nodejs-express-fast2sms\/\" \/>\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:42:05+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-18T19:21:14+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/smart-otp-add-sms-filled-hd-8-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\\\/otp-login-nodejs-express-fast2sms\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/otp-login-nodejs-express-fast2sms\\\/\"},\"author\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/#organization\"},\"headline\":\"Node.js Express OTP login with Fast2SMS Smart OTP (starter kit)\",\"datePublished\":\"2026-11-18T18:42:05+00:00\",\"dateModified\":\"2026-11-18T19:21:14+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/otp-login-nodejs-express-fast2sms\\\/\"},\"wordCount\":2238,\"publisher\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/otp-login-nodejs-express-fast2sms\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/smart-otp-add-sms-filled-hd-8-scaled.webp\",\"articleSection\":[\"API\",\"OTP\"],\"inLanguage\":\"en-IN\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/otp-login-nodejs-express-fast2sms\\\/\",\"url\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/otp-login-nodejs-express-fast2sms\\\/\",\"name\":\"Node.js Express OTP Login with Smart OTP | Fast2SMS\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/otp-login-nodejs-express-fast2sms\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/otp-login-nodejs-express-fast2sms\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/smart-otp-add-sms-filled-hd-8-scaled.webp\",\"datePublished\":\"2026-11-18T18:42:05+00:00\",\"dateModified\":\"2026-11-18T19:21:14+00:00\",\"description\":\"Build a Node.js Express OTP login page with Fast2SMS Smart OTP. Run the free starter kit in 5 steps; learn send, verify, resend, limits and DLT option.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/otp-login-nodejs-express-fast2sms\\\/#breadcrumb\"},\"inLanguage\":\"en-IN\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/otp-login-nodejs-express-fast2sms\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-IN\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/otp-login-nodejs-express-fast2sms\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/smart-otp-add-sms-filled-hd-8-scaled.webp\",\"contentUrl\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/smart-otp-add-sms-filled-hd-8-scaled.webp\",\"width\":2560,\"height\":1600,\"caption\":\"Add OTP Template window on the SMS Channel tab with entity, sender and DLT template selected and the variable buttons below the preview\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/otp-login-nodejs-express-fast2sms\\\/#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\":\"Node.js Express OTP login with Fast2SMS Smart OTP (starter kit)\"}]},{\"@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":"Node.js Express OTP Login with Smart OTP | Fast2SMS","description":"Build a Node.js Express OTP login page with Fast2SMS Smart OTP. Run the free starter kit in 5 steps; learn send, verify, resend, limits and DLT option.","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\/otp-login-nodejs-express-fast2sms\/","og_locale":"en_US","og_type":"article","og_title":"Node.js Express OTP Login with Smart OTP | Fast2SMS","og_description":"Build a Node.js Express OTP login page with Fast2SMS Smart OTP. Run the free starter kit in 5 steps; learn send, verify, resend, limits and DLT option.","og_url":"https:\/\/www.fast2sms.com\/help\/otp-login-nodejs-express-fast2sms\/","og_site_name":"Fast2SMS","article_publisher":"https:\/\/www.facebook.com\/Fast2SMS\/","article_published_time":"2026-11-18T18:42:05+00:00","article_modified_time":"2026-11-18T19:21:14+00:00","og_image":[{"width":2560,"height":1600,"url":"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/smart-otp-add-sms-filled-hd-8-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\/otp-login-nodejs-express-fast2sms\/#article","isPartOf":{"@id":"https:\/\/www.fast2sms.com\/help\/otp-login-nodejs-express-fast2sms\/"},"author":{"@id":"https:\/\/www.fast2sms.com\/#organization"},"headline":"Node.js Express OTP login with Fast2SMS Smart OTP (starter kit)","datePublished":"2026-11-18T18:42:05+00:00","dateModified":"2026-11-18T19:21:14+00:00","mainEntityOfPage":{"@id":"https:\/\/www.fast2sms.com\/help\/otp-login-nodejs-express-fast2sms\/"},"wordCount":2238,"publisher":{"@id":"https:\/\/www.fast2sms.com\/#organization"},"image":{"@id":"https:\/\/www.fast2sms.com\/help\/otp-login-nodejs-express-fast2sms\/#primaryimage"},"thumbnailUrl":"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/smart-otp-add-sms-filled-hd-8-scaled.webp","articleSection":["API","OTP"],"inLanguage":"en-IN"},{"@type":"WebPage","@id":"https:\/\/www.fast2sms.com\/help\/otp-login-nodejs-express-fast2sms\/","url":"https:\/\/www.fast2sms.com\/help\/otp-login-nodejs-express-fast2sms\/","name":"Node.js Express OTP Login with Smart OTP | Fast2SMS","isPartOf":{"@id":"https:\/\/www.fast2sms.com\/help\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.fast2sms.com\/help\/otp-login-nodejs-express-fast2sms\/#primaryimage"},"image":{"@id":"https:\/\/www.fast2sms.com\/help\/otp-login-nodejs-express-fast2sms\/#primaryimage"},"thumbnailUrl":"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/smart-otp-add-sms-filled-hd-8-scaled.webp","datePublished":"2026-11-18T18:42:05+00:00","dateModified":"2026-11-18T19:21:14+00:00","description":"Build a Node.js Express OTP login page with Fast2SMS Smart OTP. Run the free starter kit in 5 steps; learn send, verify, resend, limits and DLT option.","breadcrumb":{"@id":"https:\/\/www.fast2sms.com\/help\/otp-login-nodejs-express-fast2sms\/#breadcrumb"},"inLanguage":"en-IN","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.fast2sms.com\/help\/otp-login-nodejs-express-fast2sms\/"]}]},{"@type":"ImageObject","inLanguage":"en-IN","@id":"https:\/\/www.fast2sms.com\/help\/otp-login-nodejs-express-fast2sms\/#primaryimage","url":"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/smart-otp-add-sms-filled-hd-8-scaled.webp","contentUrl":"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/smart-otp-add-sms-filled-hd-8-scaled.webp","width":2560,"height":1600,"caption":"Add OTP Template window on the SMS Channel tab with entity, sender and DLT template selected and the variable buttons below the preview"},{"@type":"BreadcrumbList","@id":"https:\/\/www.fast2sms.com\/help\/otp-login-nodejs-express-fast2sms\/#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":"Node.js Express OTP login with Fast2SMS Smart OTP (starter kit)"}]},{"@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\/18747","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=18747"}],"version-history":[{"count":1,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/posts\/18747\/revisions"}],"predecessor-version":[{"id":19371,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/posts\/18747\/revisions\/19371"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/media\/18735"}],"wp:attachment":[{"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/media?parent=18747"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/categories?post=18747"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/tags?post=18747"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}