Deno.js fs File Handling Module to Read and Write Files inside System in TypeScript Full Project For Beginners

 

 

Features

 

 

  • Adding the FS module
  • Creating an empty directory
  • Replacing an empty directory
  • Moving a directory or file
  • Checking if a directory or file exists
  • Reading and writing JSON files
  • Reading and writing any files as strings

 

 

Deno FS

https://deno.land/std/fs/

 

Deno

https://deno.land/

 

 

 

emptyDir

 

 

import {
  emptyDir,
  emptyDirSync,
} from "https://deno.land/std@0.102.0/fs/mod.ts";

emptyDir("./foo"); // returns a promise
emptyDirSync("./foo"); // void

 

 

ensureDir

 

 

import {
  ensureDir,
  ensureDirSync,
} from "https://deno.land/std@0.102.0/fs/mod.ts";

ensureDir("./bar"); // returns a promise
ensureDirSync("./ensureDirSync"); // void

 

 

exists

 

 

import {
  exists,
  existsSync,
} from "https://deno.land/std@0.102.0/fs/mod.ts";

exists("./foo"); // returns a Promise<boolean>
existsSync("./foo"); // returns boolean

 

 

move

 

 

import { move, moveSync } from "https://deno.land/std@0.102.0/fs/mod.ts";

move("./foo", "./bar"); // returns a promise
moveSync("./foo", "./bar"); // void
moveSync("./foo", "./existingFolder", { overwrite: true });
// Will overwrite existingFolder

 

 

copy

 

 

import { copy, copySync } from "https://deno.land/std@0.102.0/fs/mod.ts";

copy("./foo", "./bar"); // returns a promise
copySync("./foo", "./bar"); // void
copySync("./foo", "./existingFolder", { overwrite: true });
// Will overwrite existingFolder

Leave a Reply