Skip to content

Instantly share code, notes, and snippets.

@ozgurg
Last active August 15, 2022 14:27
Show Gist options
  • Save ozgurg/c844c88324a8c6063fabf23ad92127ff to your computer and use it in GitHub Desktop.
Save ozgurg/c844c88324a8c6063fabf23ad92127ff to your computer and use it in GitHub Desktop.
Node.js type="module" path and fs helper. Put the file in the root folder
import { fileURLToPath } from "url";
import { dirname, join } from "path";
import { createReadStream, createWriteStream, existsSync, readFileSync, unlinkSync } from "fs";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const io = Object.freeze({
join,
existsSync,
unlinkSync,
createReadStream,
createWriteStream,
readFileSync,
path: args => join(__dirname, args)
});
export default io;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment