Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. Download free →
CLSkills
General / UtilitybeginnerNew

File Utils

Share

Create file system utility functions

Works with OpenClaude

You are a Node.js file system utilities developer. The user wants to create reusable file system utility functions for common operations like reading, writing, checking existence, and directory management.

What to check first

  • Verify Node.js version supports fs.promises (v10.0.0+) by running node --version
  • Check if your project has a package.json file in the current directory with ls -la

Steps

  1. Import the fs.promises module at the top of your utility file to use async/await syntax instead of callbacks
  2. Create a function that reads file contents using fs.promises.readFile() with 'utf-8' encoding
  3. Create a function that writes content to files using fs.promises.writeFile() with overwrite capability
  4. Create a function that checks file existence using fs.promises.access() and catch ENOENT errors
  5. Create a function that lists directory contents using fs.promises.readdir() with file type filtering
  6. Create a function that deletes files using fs.promises.unlink() with error handling
  7. Create a function that creates directories recursively using fs.promises.mkdir() with the recursive: true option
  8. Export all utility functions as a named object for modular reuse

Code

const fs = require('fs').promises;
const path = require('path');

const fileUtils = {
  async readFile(filePath) {
    try {
      const content = await fs.readFile(filePath, 'utf-8');
      return content;
    } catch (error) {
      throw new Error(`Failed to read file ${filePath}: ${error.message}`);
    }
  },

  async writeFile(filePath, content, options = {}) {
    try {
      const flag = options.append ? 'a' : 'w';
      await fs.writeFile(filePath, content, { flag, encoding: 'utf-8' });
      return true;
    } catch (error) {
      throw new Error(`Failed to write file ${filePath}: ${error.message}`);
    }
  },

  async fileExists(filePath) {
    try {
      await fs.access(filePath);
      return true;
    } catch (error) {
      return false;
    }
  },

  async listFiles(dirPath, recursive = false) {
    try {
      const files = await fs.readdir(dirPath, { withFileTypes: true });
      const fileList = files.map(file => ({
        name: file.name,
        isDirectory: file.isDirectory(),
        path: path.join(dirPath, file.name)
      }));
      return fileList;
    } catch (error) {
      throw new Error(`Failed to list directory ${dirPath}: ${error.message}`);
    }
  },

  async deleteFile(filePath) {
    try {
      await fs.un

Note: this example was truncated in the source. See the GitHub repo for the latest full version.

Common Pitfalls

  • Treating this skill as a one-shot solution — most workflows need iteration and verification
  • Skipping the verification steps — you don't know it worked until you measure
  • Applying this skill without understanding the underlying problem — read the related docs first

When NOT to Use This Skill

  • When a simpler manual approach would take less than 10 minutes
  • On critical production systems without testing in staging first
  • When you don't have permission or authorization to make these changes

How to Verify It Worked

  • Run the verification steps documented above
  • Compare the output against your expected baseline
  • Check logs for any warnings or errors — silent failures are the worst kind

Production Considerations

  • Test in staging before deploying to production
  • Have a rollback plan — every change should be reversible
  • Monitor the affected systems for at least 24 hours after the change

Quick Info

Difficultybeginner
Version1.0.0
AuthorClaude Skills Hub
generalfilesutilities

Install command:

curl -o ~/.claude/skills/file-utils.md https://claude-skills-hub.vercel.app/skills/general/file-utils.md

Related General / Utility Skills

Other Claude Code skills in the same category — free to download.

Want a General / Utility skill personalized to YOUR project?

This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.