generate the opt 4-digit and 6-digit
npm install otp-random-generator6.
bash
npm install otp-random-generator
`
Usage
Import the module in your Node.js project:
`
const { generateOTP } = require('otp-random-generator');
`
#### Generate a 6-digit OTP (default length)
`
const otp6 = generateOTP();
console.log('6-digit OTP:', otp6);
`
#### Generate an 8-digit OTP
`
const otp8 = generateOTP(8);
console.log('8-digit OTP:', otp8);
`
#### Generate a 4-digit OTP
`
const otp4 = generateOTP(4);
console.log('4-digit OTP:', otp4);
`
Example Output
`
6-digit OTP: 394857
8-digit OTP: 48392057
4-digit OTP: 1204
`
Function:
generateOTP
$3
The generateOTP function generates a random OTP of the specified length. It is designed to be simple and efficient, making it easy to integrate into your applications.
$3
- length (number): The length of the OTP to generate. The default value is 6. The length must be a positive integer.
$3
- A string representing the generated OTP.
$3
- An error if the length is less than or equal to 0`.