Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import fs from 'fs';
- import { dirname, join } from 'path';
- import { fileURLToPath } from 'url';
- const __dirname = dirname(fileURLToPath(import.meta.url));
- console.log(__dirname);
- export class FileHandler {
- read(filename = '') {
- filename = join(__dirname, '..', filename);
- return new Promise((resolve, reject) => {
- fs.readFile('data/tasks.all.json', { encoding: 'utf-8' }, (err, data) => {
- if (err) {
- reject(err)
- }else{
- resolve(JSON.parse(data));
- }
- });
- });
- }
- write(filename = '', data = '') {
- filename = join(__dirname, '..', filename);
- return new Promise((resolve, reject) => {
- fs.writeFile('data/tasks.all.json', JSON.stringify(data), { encoding: 'utf-8' }, (err) => {
- if (err) {
- reject(err);
- }
- resolve();
- })
- })
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement