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

@vitkuz/file-utils

v1.1.0

Published

Modern file system utilities for Node.js

Readme

Modern File System Utilities

A modern, Promise-based file system utility library for Node.js with TypeScript support, comprehensive error handling, and logging capabilities.

Features

  • 📁 File Operations

    • Read and write files with UTF-8 encoding
    • Copy and move files with automatic directory creation
    • Delete files safely
    • Calculate file hashes (SHA-256, MD5, etc.)
  • 📂 Directory Operations

    • Create and delete directories recursively
    • List directory contents (recursive optional)
    • Compare directory contents
    • Check if directories are empty
    • Create ZIP archives of directories
  • 🛡️ Robust Error Handling

    • Custom error types for different scenarios
    • Detailed error messages with error codes
    • Type-safe error checking utilities
  • 📝 Built-in Logging

    • Component-based logging
    • Multiple log levels (debug, info, error)
    • JSON formatting for complex data
    • Timestamps for all logs

Installation

npm install file-utils

Usage

File Operations

import { file } from '@vitkuz/file-utils';

// Read file
const content = await file.readFile('path/to/file.txt');

// Write file
await file.writeFile('path/to/new-file.txt', 'Hello World');

// Copy file
await file.copyFile('source.txt', 'destination.txt');

// Move file
await file.moveFile('old-location.txt', 'new-location.txt');

// Delete file
await file.deleteFile('unwanted-file.txt');

// Calculate file hash
const hash = await file.hashFile('important-file.txt', 'sha256');

Directory Operations

import { folder } from '@vitkuz/file-utils';

// Create directory
await folder.createDir('new-directory');

// List directory contents
const files = await folder.listDir('my-directory', true); // true for recursive

// Compare directories
const comparison = await folder.compareDirs('dir1', 'dir2');
console.log(comparison.common);        // Files in both directories
console.log(comparison.onlyInDir1);    // Files only in dir1
console.log(comparison.onlyInDir2);    // Files only in dir2

// Check if directory is empty
const isEmpty = await folder.isEmpty('some-directory');

// Create ZIP archive
await folder.zipDir('source-directory', 'archive.zip');

Error Handling

import { utils } from '@vitkuz/file-utils';

try {
  await file.readFile('non-existent.txt');
} catch (error) {
  if (utils.isErrorType(error, utils.FileNotFoundError)) {
    console.log('File not found!');
  } else if (utils.isErrorType(error, utils.PermissionError)) {
    console.log('Permission denied!');
  }
}

Logging

The library includes built-in logging that provides detailed information about operations:

// Logs are automatically generated for all operations
await file.writeFile('example.txt', 'content');
// [2024-01-20T10:30:00.000Z] DEBUG files - Writing to file: example.txt

Error Types

  • FSError - Base error class
  • FileNotFoundError - File does not exist
  • DirectoryNotFoundError - Directory does not exist
  • PathExistsError - Path already exists
  • InvalidPathError - Path is invalid
  • PermissionError - Insufficient permissions
  • HashError - Hash calculation failed
  • ZipError - ZIP operation failed

Development

# Install dependencies
npm install

# Run tests
npm test

# Build the project
npm run build

# Watch mode during development
npm run dev

# Lint the code
npm run lint

# Format the code
npm run format

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.