Otp Verification in nodejs

0 votes
I want to send an otp to the user who is signing up for the web app by SMS and email to validate their email and phone number.

Is there an NPM package for transmitting and validating OTPs, or do I have to develop my own?
Jun 10, 2022 in Node-js by Vaani
• 7,020 points
2,492 views

1 answer to this question.

0 votes

Yes, a package named sendotp exists. This is solely used to deliver OTP through SMS.

You may discover a variety of examples in npmjs to help you complete your assignment.

However, I believe that implementing your own approach for transmitting and confirming OTP is preferable. Because utilising packages may result in the addition of methods that you do not require or the absence of functionality that you require.

For email verification, you may use Nodemailer, and for SMS verification, you can utilise Twiiolio. Create a random string and send it to the user through SMS or email. If you use MongoDB, you can check when the otp is formed and from there see how much time has elapsed since it was delivered.

You can use the msg91 for sending the otp to users.
Login to msg91 and get your template_id and api_key.
using msg91 api with the axios.

const axios = require('axios');

async function  sendOtpTOUser(phone) {
 const  template =  "template _id";
 const  apiKey = "api_key";         
 const sendotp = "https://api.msg91.com/api/v5/otp?template_id="+template+"&mobile="+phone+"&authkey="+apiKey;
                 let request_options1 = {
                  method: 'get',
                  url: sendotp
              };  
     
  let otpResponse = await axios(request_options1);
  console.log(otpResponse.data)  
  return otpResponse.data;              
}

it will return the object as

{ request_id: '3166686e7867313634383535', type: 'success' }
answered Jun 10, 2022 by Neha
• 8,940 points

Related Questions In Node-js

0 votes
1 answer

How do I “include” functions from my other files in nodejs?

Hello @kartik, You require any js file,so you just ...READ MORE

answered Jul 9, 2020 in Node-js by Niroj
• 82,840 points
2,356 views
0 votes
1 answer

Error:npm WARN unmet dependency in nodejs

Hii @kartik, Following are the possible solution : Manually ...READ MORE

answered Jul 12, 2020 in Node-js by Niroj
• 82,840 points
4,178 views
0 votes
1 answer

How to get the _id of inserted document in Mongo database in NodeJS?

Hello @kartik, A shorter way than using second ...READ MORE

answered Sep 7, 2020 in Node-js by Niroj
• 82,840 points
10,703 views
0 votes
1 answer

How to run app.js in nodejs?

Hello @kartik, Assuming I have node and npm properly installed on the ...READ MORE

answered Oct 13, 2020 in Node-js by Niroj
• 82,840 points
1,717 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,265 views
0 votes
1 answer
0 votes
0 answers

Can't we SEO Mern Stack Applications and reactjs Applications?

I created a MERN Stack Application which ...READ MORE

Mar 13, 2022 in Digital Marketing by Kichu
• 19,050 points
308 views
0 votes
1 answer

How to schedule a google meet and get the meet link in NodeJs?

To create a Google Meet, you'll need ...READ MORE

answered May 27, 2022 in Node-js by Neha
• 8,940 points
2,017 views
0 votes
1 answer

What is the role of Nodejs and Express in a MERN stack web application when GraphQL is also used?

Node.js is a JavaScript runtime environment, which ...READ MORE

answered May 27, 2022 in Node-js by Neha
• 8,940 points
866 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP