Node.js Express Project to Send OTP SMS Messages to Mobile Number Using Fast2SMS API in Javascript
Mar 12, 2025
Buy the full source code of the application at Paypal in USD Currency here:
https://procodestore.com/index.php/product/node-js-express-project-to-send-otp-sms-messages-to-mobile-number-using-fast2sms-api-in-javascript/
#fast2sms #nodejs #express
Visit my Online Free Media Tool Website
https://freemediatools.com/
Buy Premium Scripts and Apps Here:
https://procodestore.com/
Welcome Folks My name is Gautam and Welcome to Coding Shiksha a Place for All Programmers. You can learn Web Development and Programming Tutorials.
Donate to Our Youtube Channel at :
https://www.instamojo.com/@geekygautam1997
Show More Show Less View Video Transcript
0:01
uh Hello friends today in this tutorial
0:03
I will be showing you that how to
0:04
receive OTP message inside your node CHS
0:08
application for any sort of verification
0:11
inside your application for login
0:13
application or any sort of so for doing
0:16
this we will be using this API called as
0:18
fast to SMS so basically if you go to
0:22
this website here fast to sms.com so you
0:25
just need to register on this website
0:28
and after registration you will get this
0:30
interface and you will get get some free
0:33
credits where you can test out the
0:34
application so you will see this is a
0:36
brand new account that I created inside
0:39
this website and it offers its own API
0:42
which is this section Dev API and after
0:45
that you the second option is this API
0:48
key so select this option and uh it will
0:51
automatically generate your API key you
0:53
can also re regenerate it so this is my
0:56
API key simply copy this so accordingly
0:59
just sign up and you will have your own
1:01
API key simply copy this and now inside
1:05
your node shares project guys so this is
1:07
my node Chase project let me build it
1:09
from
1:11
scratch
1:13
and let
1:16
me move out of this directory let me
1:19
also close this and make a new directory
1:22
which is node OTP project I will go into
1:26
this directory node OTP project
1:30
and I will open this inside my visual
1:32
studio code text editor so now we will
1:35
initialize the empt package.json file
1:38
which contains all the information about
1:40
the project now we need to install this
1:42
dependency which is uh this is a node
1:45
CHS dependency which offers uh a great
1:49
interface to this website which is fast
1:51
to SMS this is a module here so you can
1:55
search for this module
1:57
fast-2 D SMS so this is a module node
2:01
Chase module which interacts with this
2:03
API so if you search for this module the
2:06
very first link which comes in you will
2:09
see this is the module here it contains
2:11
284 weekly downloads so simply you need
2:14
to install this fast -2- SMS so it will
2:19
hardly Take 5 Seconds to install this
2:21
module after installation you can use
2:24
this module so simply I will create the
2:26
index.js file the starting point of the
2:29
application now we will simply ex import
2:32
this module fast to SMS we will require
2:36
it
2:37
fast-2 SMS so after requiring this now
2:41
we simply need to uh include the API key
2:45
guys so inside options so just create
2:49
options variable here and inside this
2:51
object it contains a parameter called as
2:54
authorization so here you need to
2:56
include your own API key so just go to
3:00
your website dashboard I have already
3:03
shown you how to register it simply copy
3:05
this API key and paste it
3:09
here and after that guys the second
3:12
parameter is numbers here you can also
3:14
provide uh bul numbers also multiple
3:18
numbers so if you want to send out
3:21
multiple messages at one time you can do
3:23
it so numbers
3:26
colon and then inside this array you can
3:29
pass the number
3:30
so numbers should be passed without
3:33
mentioning the country code so I will
3:35
pass my number you will see just write
3:37
it and also the second parameter will be
3:40
the message guys whatever message that
3:42
you want to send in my case I will send
3:44
OTP you can send out anything so we will
3:47
say this is a test message test OTP code
3:53
message your OTP
3:57
is code is some random value 5 6 7 8 so
4:04
now we need to send this to the number
4:07
that we mentioned
4:08
here so for sending it it is very simple
4:11
we will use the module which is fast to
4:13
SMS and this contains a send method send
4:16
message method and here we will provide
4:18
the options that's it so now guys this
4:21
will return a this is a Asing function
4:24
this will return a promise so we can
4:27
display the response to the user simply
4:30
in the console that if the message is
4:32
sent or
4:33
not and if any sort of error take place
4:36
we can catch it by do catch and we can
4:39
display the error in case of error like
4:42
this console log
4:45
error so basically now if I launch the
4:49
application if I
4:52
see uh if I write here node
4:56
index.js so you will see it will send
4:59
out the OTP and now you will see it will
5:01
return out the request ID to this and
5:04
message SMS sent successfully so we have
5:07
successfully send the OTP message let me
5:09
show it uh this will be let me show it
5:12
let me move this window a little bigger
5:15
so let me show the mobile where I
5:17
received this so you will see guys if if
5:20
I can show you like
5:22
this this is the message is received
5:24
here you will see I just want to
5:30
you can see that dear user this is a
5:32
test OTP code message your OTP code is
5:36
5678 so I just received it right now you
5:39
will see that so if you do it you can
5:42
also receive it on your mobile phone as
5:44
well so just need to provide your number
5:46
and after that it will just uh send out
5:49
to you it is damn easy using this API
5:54
and if any if I make any sort of error I
5:57
provide a wrong number and let me run it
6:00
once again you will see that now it will
6:02
show you error that it is a invalid
6:05
number so now it will show you this
6:07
error so this is a very simple node
6:10
module by which you can send out OTP SMS
6:13
messages to any number using node CHS
6:15
using fast to SMS
6:17
API and also guys you can make it as a
6:21
express application you can give take
6:23
the input from the user so we can do it
6:26
we can convert this application so
6:28
simply
6:30
install Express this is very easy so I
6:34
just want to convert this to a express
6:37
application where we can take the number
6:39
as the input so simply we will say we
6:42
will make the index. HTML and we will
6:45
have the form which will make a post
6:48
request send message and the method will
6:51
be post and inside this we will have
6:54
input type of number
6:59
or we can simply say text input type of
7:02
text and here we will say number that's
7:04
it so here placeholder we will say enter
7:07
mobile that's it so this is
7:12
required after that we will have the
7:14
button to send
7:17
message and then we will just say this
7:20
is of type submit that's it so now we
7:24
need to make this post request so inside
7:26
index. jsk SK we need to first of all
7:29
import
7:30
Express so we will say V Express
7:37
required so conab Express and then we
7:41
need to
7:42
app.get when we load the page for the
7:44
very first time the get request we need
7:47
to load the index. HTML file so we will
7:49
say request. send file and durame plus
7:54
uh
7:55
index.html so we need to start the
7:57
server so right here we will say app
8:00
do listen and we will listen on Port
8:03
5,000 and we will say app is listening
8:09
on
8:11
Port 5,000 so you will see that guys if
8:15
I run this application let me comment
8:18
out this code here so that it doesn't
8:21
again send out the message so now if I
8:24
run this you will see
8:31
you can see app is listening on Port
8:33
5,000 so basically if I go to my
8:35
homepage you will see now you will see
8:38
Local Host
8:39
5,000 you will see this is a mobile
8:41
number and send message and we also need
8:44
a field for which we can provide a
8:46
message to the user so we will simply
8:49
say input type text and we will say
8:54
message and we will say placeholder
8:57
enter your message
9:01
and this also is
9:04
required so refresh it and now you will
9:07
see two input Fields will be there first
9:09
for the number and second for the
9:11
message and then we have a simple button
9:13
of send message so simply we need to
9:16
make this post request so we will say
9:19
app. get sorry
9:22
post send message and here we can
9:25
receive these parameters simply by
9:29
requesting this uh by console logging
9:34
it request. body do message and request
9:40
do body.
9:43
number so we have provided these as a
9:46
name parameters so this is very much
9:48
useful it needs to be same because we
9:50
are uh getting this using this name
9:53
parameter so if you launch this
9:56
application again and if if I send out
10:00
this uh any number here if I write
10:02
anything
10:06
here if I click send you will see it
10:10
cannot read it
10:13
because uh we need to for this we need
10:16
to require body passer middleware so
10:19
whenever you are working with any form
10:21
in Express you need this middleware this
10:23
is a built-in middleware you need not
10:25
have to inst install it and then you
10:28
need to initialize this this is very
10:29
easy body pass. URL encoded extended to
10:33
false and then we need to write app do
10:37
use body pass. Json so just write these
10:40
two lines and then your problem will be
10:42
solved and simply once again refresh
10:45
your
10:46
application and send
10:50
out so again send
10:56
out so you will see that guys now the
10:59
these information is printed in the
11:00
console so we are successfully getting
11:02
it from the HTML form inside of express
11:06
application now we simply need to move
11:08
this code which you see here so simply
11:10
you need to move this code here simply
11:13
inside this post request so we can do
11:17
this like this so we can make this
11:20
inside a separate function we will say
11:22
send
11:23
message so we can make this as a async
11:28
function
11:31
async function
11:34
so we can paste this code here like
11:45
this uh like this so function send
11:49
message so now inside this we can call
11:52
this method here send
11:54
message and we can pass the message
11:58
which will be request body. message and
12:01
the number as well request. body. number
12:04
so here we can receive this message.
12:10
number and also we can pass the response
12:13
here response so just pass this response
12:17
object as well so response is there so
12:20
whenever it is successful we will simply
12:21
say to the user we will send out a
12:23
response that
12:25
uh SMS sent successfully
12:32
SMS
12:38
o if any sort of error take place then
12:40
we can say simply send
12:45
out some error Tak on place that's it so
12:50
now we need to replace the number here
12:52
so simply you need to replace it by the
12:55
number that you are receiving here so
12:59
simply just replace number here and for
13:02
the message simply replace this with the
13:06
message so inside this
13:09
field replace it by message that's it so
13:13
now we have made this application
13:16
Dynamic so we can provide the number and
13:19
the message dynamically so once again
13:22
refresh the
13:26
application so again you will see
13:31
it is saying SMS code sent successfully
13:34
here you will see
13:35
that so once again if I show
13:40
you so if I zoom the screen you will see
13:43
once again it is
13:45
received on my phone here so you will
13:51
see this is a latest message which is
13:54
received
13:55
here I'm gotam owner of coding seure so
13:59
in this easy way guys you can send out
14:01
otps SMS messages to any mobile inside
14:05
node chairs I have shown you all the
14:07
source code and if you want the full
14:10
source code you can go to the video
14:11
description link I have given this link
14:14
in the video description you can check
14:16
out and download all the source code
14:17
please hit the like button subscribe to
14:19
channel and I will be seeing you in the
14:21
next video
#Programming
#Text & Instant Messaging
#Scripting Languages
