Fig Docs
  • 🏠Welcome to Fig
  • 👋Get Started
    • Download and Install
    • `fig home`
      • My Apps
      • The Sidebar
      • Settings
    • The Fig App Store
    • Hotkeys
  • 💪Autocomplete
  • 😀The Fig CLI
    • 1. Fig Overrides
    • 2. Fig Aliases
    • 3. $FIGPATH
    • 4. Fig Apps
  • 📖Interactive Runbooks
    • Form Elements
      • Input
      • Textarea
      • Dropdown
      • Checkboxes
      • Buttons
    • Templating & Interpolation
    • Scripting Language (Psilo)
      • Full List of Functions
    • Running Runbooks
    • Full Examples
  • ⚒️ Build your own CLI
    • `fig build`
    • .fig Files
  • 🧰Build your own App
    • Get Started
    • App Lifecycle
    • Key Concepts
      • Running Shell Commands
      • Reading Environment Variables
      • Accessing Files & Saving Data
      • Loading Local Resources
    • Window Managment
      • Setting Window Properties
      • Repositioning the Window
      • Focusing & Blurring the Window
    • Advanced
      • Creating a Pseudo-Terminal Session
  • Other
    • Fig for Teams
    • Security & Privacy
    • FAQ
    • Contact Us
  • Interactive Runbooks
Powered by GitBook
On this page
  • Reading and Writing App Files
  • Reading and Writing User Files
  • Normalize File paths
  1. Build your own App
  2. Key Concepts

Accessing Files & Saving Data

PreviousReading Environment VariablesNextLoading Local Resources

Last updated 4 years ago

You can save data to the browser storage or to the local file system.

  • Using browser APIs like , & .

  • Using fig.appwrite and fig.appread

  • Using fig.fwrite and fig.fread

Reading and Writing App Files

Every app has a directory where they can read and write freely. This can be used for storing user data or preferences.

Read data from file relative to ~/.fig/apps/app-name/ where app-name is defined by the fig:app .

fig.appread('prefs.json', (data, error) => {

})

Write data to file relative to ~/.fig/apps/app-name/

let data = JSON.stringify({theme: "dark"})
fig.appwrite(path, data, (error) => {

})

Reading and Writing User Files

Write data to file at path. The path is relative to the user's working directory when they launch your app.

To write a file to the path.

fig.fwrite(path, data, (error) => {
  
})

Read data from file at path

fig.fread(path, (data, error) => {
  
})

Normalize File paths

fig.normalizeFilepath

fig.normalizeFilePath(`${fig.env.PWD}/..`, (normalized) => { 
    console.log(normalized) 
})
🧰
LocalStorage
SessionStorage
IndexedDB
meta tag