Create file system utility functions
✓Works with OpenClaudeYou 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 runningnode --version - Check if your project has a
package.jsonfile in the current directory withls -la
Steps
- Import the
fs.promisesmodule at the top of your utility file to use async/await syntax instead of callbacks - Create a function that reads file contents using
fs.promises.readFile()with 'utf-8' encoding - Create a function that writes content to files using
fs.promises.writeFile()with overwrite capability - Create a function that checks file existence using
fs.promises.access()and catch ENOENT errors - Create a function that lists directory contents using
fs.promises.readdir()with file type filtering - Create a function that deletes files using
fs.promises.unlink()with error handling - Create a function that creates directories recursively using
fs.promises.mkdir()with therecursive: trueoption - 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
Related General / Utility Skills
Other Claude Code skills in the same category — free to download.
Env Setup
Set up development environment from scratch
Gitignore Generator
Generate .gitignore for any project type
NPM Publish
Prepare and publish npm package
Error Boundary
Create error boundary components
Feature Flag
Implement feature flag system
Config Manager
Create application configuration manager
Date Time Helper
Create date/time utility functions
String Utils
Create string manipulation utilities
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.