New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

grom-utils

Package Overview
Dependencies
Maintainers
0
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grom-utils

A lightweight utility package for simplified error handling, validation, and API responses.

  • 1.1.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
45
decreased by-83.7%
Maintainers
0
Weekly downloads
 
Created
Source

grom-utils

A utility package for Express.js applications offering simplified async handling, error responses, validation, rate limiting, and logging.

🚀 Overview

Grom is a powerful utility package designed to enhance Express.js applications by providing a standardized approach to error handling, input validation, rate limiting, structured responses, and logging. It simplifies backend development by enforcing best practices and reducing boilerplate code.

❓ Problem Statement

Developers often face repetitive tasks in Express.js applications, such as:

  • Handling async errors properly.
  • Validating user input against expected schemas.
  • Preventing API abuse with rate limiting.
  • Standardizing API responses.
  • Implementing structured logging.

Grom solves these problems by offering a robust, modular utility class that integrates seamlessly into Express.js applications.

📦 Installation

npm install grom-utils

Features

  • Async Handler: Wrap async functions to catch errors.
  • Error Checker: Throw custom API errors with ease.
  • API Responses: Standard and paginated API responses.
  • Input Validation: Schema-based input validation.
  • Rate Limiting: Simple middleware to limit requests per IP.
  • Logging: Colorful, timestamped logs.

🛠 Usage

1. Async Error Handling (grAsyncHandler)

Problem: Handling errors in async Express.js routes requires repetitive try-catch blocks.

Solution: Grom wraps async functions to automatically catch errors and forward them to Express middleware.

Example:

import { grAsyncHandler } from "grom-utils";

app.get("/data", grAsyncHandler(async (req, res) => {
    const data = await fetchData(); // Assume async function
    res.json({ success: true, data });
}));

2. Schema-Based Input Validation (grValidate)

Problem: Manually checking request payloads for type mismatches is tedious and error-prone.

Solution: Grom validates data against a predefined schema and throws an error if mismatched.

Example:

import { grValidate } from "grom-utils";

const userSchema = { name: "string", age: "number" };

app.post("/register", (req, res) => {
    grValidate(userSchema, req.body);
    res.json({ message: "User registered successfully" });
});

3. API Response Standardization (grResponse)

Problem: API responses often lack consistency in structure and formatting.

Solution: Grom provides a standard response format with status codes, messages, and metadata.

Example:

import { grResponse } from "grom-utils";

app.get("/status", (req, res) => {
    res.json(grResponse(200, { status: "OK" }, "Service is running"));
});

4. Custom Error Checking (grCheck)

Problem: Developers often need to enforce custom conditions before proceeding.

Solution: Grom throws an API error if a condition is false.

Example:

import { grCheck } from "grom-utils";

app.post("/order", (req, res) => {
    grCheck(req.body.items.length > 0, 400, "Order cannot be empty");
    res.json({ message: "Order placed successfully" });
});

5. Rate Limiting Middleware (grRateLimit)

Problem: APIs are vulnerable to abuse through excessive requests.

Solution: Grom limits requests per IP address within a specified time window.

Example:

import { grRateLimit } from "grom-utils";

app.use(grRateLimit(5, 10000)); // Max 5 requests per 10 sec

6. Structured Logging (grLogger)

Problem: Logs are often unstructured, making debugging difficult.

Solution: Grom provides color-coded logs with timestamps.

Example:

import { grLogger } from "grom-utils";

grLogger("info", "Server started on port 3000");

Functions

  • grAsyncHandler
  • grCheck
  • grResponse
  • grValidate
  • grRateLimit
  • grLogger

🎯 Why Use Grom?

  • ✅ Reduces repetitive boilerplate code.
  • ✅ Improves API security and reliability.
  • ✅ Enforces best practices in Express.js.
  • ✅ Easy integration into existing projects.

📜 License

MIT License

📞 Support

For issues and feature requests, open an issue on GitHub.

Dhruv Sharma ([@dhruv-sharma007])

👥 Contributors

Jasraj Chouhan ([@Jasraj Chouhan])

Become contributor in this project

Keywords

FAQs

Package last updated on 09 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc