Outline
Deno provides a file system library, fs
, that is very similar to Node's. You can check its documentation here. Here's the URL you use for importing the module: "https://deno.land/std/fs/mod.ts".
There are many ways to create files in Deno, but the simplest way is to use the Deno.writeTextFile
and Deno.writeTextFileSync
methods. They both do the same thing, but the first returns a promise and needs to be await
ed. The first parameter to the method is the file's name, and the second is the string that will be written to the file.
To run a file that needs to read from the file system, you need the --allow-read
flag. To write to the system, you need the --allow-write
. Currently, to run a file that uses the Deno.writeTextFile
or Deno.writeTextFileSync
methods, the --unstable
flag needs to be used. That's because it's currently still an unstable API and may change. Eventually you won't need that flag, but for now you need to use it.
For this assignment, write a script that checks to see if a file exists. If it does, log a message to the console telling the user that. If it doesn't, then write the file to the system. Use a command line flag as the name of the file, but make sure to use a fallback value for the flag.