taskmanagerutil
Version:
A task management package with CRUD, search, and file operations.
31 lines (26 loc) • 585 B
JavaScript
const fs = require('fs');
const path = require('path');
function ensureDirectory(dirPath) {
if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath, { recursive: true });
}
}
function readFile(filePath) {
try {
return fs.readFileSync(filePath, 'utf-8');
} catch (err) {
throw new Error('Failed to read file: ' + err.message);
}
}
function writeFile(filePath, data) {
try {
fs.writeFileSync(filePath, data);
} catch (err) {
throw new Error('Failed to write file: ' + err.message);
}
}
module.exports = {
ensureDirectory,
readFile,
writeFile
};