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,070 points
4,803 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
• 9,020 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
3,440 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
6,327 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
13,785 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
3,017 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,941 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,466 views
0 votes
1 answer
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
• 9,020 points
3,899 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
• 9,020 points
2,676 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