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

@devlocore/apipack

v1.2.6

Published

A TypeScript utility library for Express.js applications, providing Zod validation middleware, logging helpers, and project utilities.

Downloads

970

Readme

@devlocore/apipack

A TypeScript utility library for Express.js applications, providing Zod validation middleware, logging helpers, and project utilities.

Installation

npm install @devlocore/apipack

Peer Dependencies

This package requires the following peer dependencies:

npm install express zod

Modules

This package exports three modules:

  • @devlocore/apipack/zod - Zod validation middleware for Express
  • @devlocore/apipack/helper - Project utility helpers
  • @devlocore/apipack/log - Logging utilities

Zod Validation Middleware

Middleware functions to validate Express request body, params, and query using Zod schemas.

Import

import {
  validateBody,
  validateParams,
  validateQuery,
  sendErrors,
  zodSchema_Id,
  zodSchema_IdString,
  zodSchema_Name
} from '@devlocore/apipack/zod';

Usage

Validate Request Body

import express from 'express';
import { z } from 'zod';
import { validateBody } from '@devlocore/apipack/zod';

const app = express();
app.use(express.json());

const userSchema = z.object({
  name: z.string(),
  email: z.string().email(),
  age: z.number().optional()
});

app.post('/users', validateBody(userSchema), (req, res) => {
  // req.body is validated
  res.json({ message: 'User created', data: req.body });
});

Validate Request Params

import { z } from 'zod';
import { validateParams, zodSchema_Id } from '@devlocore/apipack/zod';

// Using built-in schema
app.get('/users/:id', validateParams(zodSchema_Id), (req, res) => {
  // req.params.id is validated as a number
  res.json({ userId: req.params.id });
});

// Using custom schema
const customParamsSchema = z.object({
  userId: z.number(),
  postId: z.number()
});

app.get('/users/:userId/posts/:postId', validateParams(customParamsSchema), (req, res) => {
  res.json({ userId: req.params.userId, postId: req.params.postId });
});

Validate Query Parameters

import { z } from 'zod';
import { validateQuery } from '@devlocore/apipack/zod';

const querySchema = z.object({
  page: z.number().optional(),
  limit: z.number().optional(),
  search: z.string().optional()
});

app.get('/users', validateQuery(querySchema), (req, res) => {
  // Access validated query via req.validatedQuery
  const { page, limit, search } = req.validatedQuery;
  res.json({ page, limit, search });
});

Built-in Schemas

  • zodSchema_Id - { id: z.number() }
  • zodSchema_IdString - { id: z.string() }
  • zodSchema_Name - { name: z.string() }

Automatic Type Conversion

The middleware automatically converts string values to their expected types:

  • Strings to numbers (for params and query)
  • Strings to booleans (for params and query)
  • Strings to dates (for body, params, and query)

Helper Utilities

Utility functions for project path resolution and environment detection.

Import

import {
  projectRoot,
  workingDirectory,
  isProductionEnvironment
} from '@devlocore/apipack/helper';

Usage

import { projectRoot, workingDirectory, isProductionEnvironment } from '@devlocore/apipack/helper';

// Get the project root directory (where package.json is located)
console.log('Project root:', projectRoot);

// Get the current working directory
console.log('Working directory:', workingDirectory());

// Check if running in production
if (isProductionEnvironment()) {
  console.log('Running in production mode');
} else {
  console.log('Running in development mode');
}

Logging Utilities

Utilities for enhanced console logging with timestamps and log file redirection.

Import

import { logWithDatePrefix, redirectLogs } from '@devlocore/apipack/log';

Usage

Add Timestamps to Console Output

import { logWithDatePrefix } from '@devlocore/apipack/log';

// Enable date prefixes for all console methods
logWithDatePrefix();

console.log('Hello world');
// Output: [12/1/2025, 10:30:00 AM] Hello world

console.error('An error occurred');
// Output: [12/1/2025, 10:30:00 AM] An error occurred

Redirect Logs to Files

import { redirectLogs } from '@devlocore/apipack/log';

// Redirect stdout and stderr to log files
// Creates files in {projectRoot}/logs/ directory
// Files are named with timestamp: DD-MM-YYYY HH-mm-ss.out and .err
redirectLogs();

console.log('This goes to the .out file');
console.error('This goes to the .err file');

TypeScript Support

This package is written in TypeScript and includes type definitions. The middleware functions provide full type inference for your Zod schemas.

import { z } from 'zod';
import { validateBody } from '@devlocore/apipack/zod';

const schema = z.object({
  name: z.string(),
  age: z.number()
});

// TypeScript will infer the body type from the schema
app.post('/users', validateBody(schema), (req, res) => {
  // req.body is typed as { name: string; age: number }
});

License

See LICENSE.txt

Author

DevloCore