Reading/Writing Files

Reading/Writing Files

Most of the methods from fs/promises and fs-extra are globally available

Create a File

// "home" is a method that wraps `path.resolve` based on your home directory
let filePath = home("projects", "kit", "note.txt")
// writes a file to the filePath using `fs-extra's` "outputFile"
await outputFile(filePath, `Drink more water`)

Select and Edit a File

// "selectFile" uses Finder's file selector
let filePath = await selectFile()
let contents = await readFile(filePath, "utf-8")
// Pass the text contents into the editor to quickly edit a file
let result = await editor(contents)
await writeFile(filePath, result)
Discuss Post