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 🙏

© 2025 – Pkg Stats / Ryan Hefner

node-easyvalid

v1.1.1

Published

A lightweight, powerful validation library for Node.js backend development. Simplify user input validation, error handling, and data integrity in Express APIs and JavaScript applications with ease.

Readme

Node EasyValid

A lightweight, powerful validation library for Node.js backend development. Simplify user input validation, error handling, and data integrity in Express APIs and JavaScript applications with ease.

Features

  • Truthy/falsy value checks
  • Array validation for multiple inputs
  • Email format validation
  • String length constraints
  • Numeric value validation
  • Custom error messages and HTTP status codes
  • Seamless integration with Express.js and other Node.js frameworks

Installation

npm install node-easyvalid

Quick Start

Basic usage example:

const { isTrue, isEmail, minLength } = require("node-easyvalid");

try {
    isTrue("hello", "Value is required"); // Passes
    isEmail("[email protected]", "Invalid email"); // Passes
    minLength("password123", 8, "Password too short"); // Passes
    isTrue("", "Cannot be empty"); // Throws Error
} catch (error) {
    console.log(error.message); // Custom error message
    console.log(error.statusCode); // Default 400 or custom
}

1. isTrue(value, [message], [statusCode])

What it does: Checks if something exists (not empty, not zero, not nothing).

Syntax: value: The thing you’re checking (like a name or number). message (optional): What to say if it fails (default: "Validation Failed"). statusCode (optional): A number for errors (default: 400, good for web apps).

Returns: true if okay, or throws an error if not.

Example

const { isTrue } = require("node-easyvalid");

try {
  let name = 'John';
  let emptyValue = "";
  isTrue(name, "Name is missing!"); // Returns true
  isTrue(emptyValue, "Name is missing!"); // Throws "Name is missing!"
} catch (error) {
  console.log(error.message); // "Name is missing!"
}

2. isTrues(array, [message], [statusCode])

What it does: Makes sure every item in a list exists (not empty or nothing).

Syntax: array: A list of things (like ["apple", "banana"]). message (optional): Error message if something’s wrong (default: "Validation Failed").

statusCode (optional): Error number (default: 400).

Returns: true if all items are okay, or throws an error if not. Example:

const { isTrues } = require("node-easyvalid");

try {
  isTrues(["cat", "dog"], "List can’t have empty items!"); // Returns true
  isTrues(["cat", ""], "List can’t have empty items!"); // Throws error
} catch (error) {
  console.log(error.message); // "List can’t have empty items! at index 1"
}

3. isEmail(email, [message], [statusCode])

What it does: Checks if something looks like an email (e.g., "[email protected]").

Syntax: email: The email you’re checking. message (optional): Error message if it’s wrong (default: "Invalid email format"). statusCode (optional): Error number (default: 400).

Returns: true if it’s an email, or throws an error if not.

Example

const { isEmail } = require("node-easyvalid");

try {
  isEmail("[email protected]", "That’s not an email!"); // Returns true
  isEmail("not-an-email", "That’s not an email!"); // Throws "That’s not an email!"
} catch (error) {
  console.log(error.message); // "That’s not an email!"
}

4. minLength(value, min, [message], [statusCode])

What it does: Makes sure text is long enough (like a password).

Syntax: value: The text to check. min: The smallest length allowed (a number). message (optional): Error message if too short (default: "Must be at least {min} characters"). statusCode (optional): Error number (default: 400).

Returns: true if long enough, or throws an error if not.

Example

const { minLength } = require("node-easyvalid");

try {
  minLength("password123", 8, "Password too short!"); // Returns true
  minLength("pass", 8, "Password too short!"); // Throws "Password too short!"
} catch (error) {
  console.log(error.message); // "Password too short!"
}

5. isNumber(value, [message], [statusCode])

What it does: Checks if something is a number (like 42 or "42").

Syntax: value: The thing to check. message (optional): Error message if it’s not a number (default: "Must be a number"). statusCode (optional): Error number (default: 400).

Returns: true if it’s a number, or throws an error if not.

Example

const { isNumber } = require("node-easyvalid");

try {
  isNumber(25, "Age must be a number!"); // Returns true
  isNumber("25", "Age must be a number!"); // Returns true
  isNumber("twenty", "Age must be a number!"); // Throws "Age must be a number!"
} catch (error) {
  console.log(error.message); // "Age must be a number!"
}

Real-World Use Cases

1. Express API - User Registration

Validate user inputs in an Express API for registration:

const { isTrue, isEmail, minLength, isNumber } = require("node-easyvalid");

// Registration endpoint
app.post("/api/register", (req, res, next) => {
    try {
        const { username, email, password, age } = req.body;

        // Validate inputs
        isTrue(username, "Username is required",400);
        minLength(username, 3, "Username must be at least 3 characters");
        isEmail(email, "Please provide a valid email");
        minLength(password, 8, "Password must be at least 8 characters");
        isNumber(age, "Age must be a number");

        // Simulate successful registration
        res.status(201).json({
            message: "User registered successfully",
            user: { username, email, age },
        });
    } catch (error) {
        res.status(error.statusCode || 500).json({ message: error.message || "Internal Server Error" });
    }
});

Questions?

If you’re stuck, feel free to ask! You can email [email protected]