npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@jehankandy/otp-core-email-core

v1.0.0

Published

OTP and Email core functions

Readme

Core functions for Genarate OTP and Send Email

About NPM

Core utilities for OTP generation and sending secure login emails using Node.js and Nodemailer. Designed for MVC backends, Express apps, and password-less authentication flows.

✨ Features

  • 🔐 Secure OTP generation

  • 📧 Beautiful, production-ready OTP email template

  • ⚡ Simple API (plug & play)

  • 🧩 MVC-friendly (Controller → Service → Utility)

  • 🔄 Reusable email sender

  • 🚀 Works with Gmail SMTP (extensible)

🔧 Requirements

  • Your host application must provide the following environment variables:

[email protected]
EMAIL_PASSWORD=your-app-password
  • The package does NOT manage .env files — this is intentional and follows npm best practices

📁 Package Exports


const {
  defaultLoginOTPEmail,
  genarateOTP,
  sendEmail
} = require("otp-core-email-core");

| Function | Description | |------------------------|---------------------------------| | generateOTP(length) | Generates a secure one-time password (OTP) | | defaultLoginOTPEmail() | Sends a styled OTP login email | | sendEmail() | Low-level email sending utility |

🔐 Generate OTP


const { genarateOTP } = require("otp-core-email-core");

const otp = genarateOTP();      // default length: 8
const otp6 = genarateOTP(6);    // custom length

📧 Send OTP Login Email (Recommended)

  • This is the main function of the package.

const { defaultLoginOTPEmail, genarateOTP } =
  require("otp-core-email-core");

const otp = genarateOTP();

await defaultLoginOTPEmail({
  email: "[email protected]",
  otp,
  project: "My Application"
});

What it does

  • Uses a modern HTML email template

  • Sends a password-less login OTP

  • Displays project branding

  • Explains OTP expiration and security

📨 Send Custom Email (Optional)

  • You can also use the raw email sender.

const { sendEmail } = require("otp-core-email-core");

await sendEmail({
  project: "My App",
  to: "[email protected]",
  subject: "Welcome!",
  html: "<h1>Hello World</h1>"
});

🧱 MVC Example (Express Controller)


const {
  defaultLoginOTPEmail,
  genarateOTP
} = require("otp-core-email-core");

exports.sendLoginOTP = async (req, res) => {
  try {
    const { email } = req.body;

    if (!email) {
      return res.status(400).json({ message: "Email required" });
    }

    const otp = genarateOTP();

    await defaultLoginOTPEmail({
      email,
      otp,
      project: "MVC OTP App"
    });

    res.json({ message: "OTP sent successfully" });
  } catch (err) {
    console.error(err);
    res.status(500).json({ message: "Failed to send OTP" });
  }
};

🛡️ Security Notes

  • OTPs are random and unpredictable

  • Email explains expiration rules

  • No passwords are stored

  • Recommended to:

    • Store OTP hash in DB / Redis
    • Add rate-limiting on OTP requests

🧠 Design Decisions

  • No global variables

  • No framework coupling

  • No .env handling inside library

  • Clean separation of concerns

  • Ready for production & scaling

📄 License

MIT License

👨‍💻 Author

  • Jehan Weerasurit