# Accessing Files & Saving Data

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

* Using browser APIs like [LocalStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage), [SessionStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage) & [IndexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API).
* Using `fig.appwrite` and `fig.appread`
* Using `fig.fwrite` and `fig.fread`&#x20;

### **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` [meta tag](/fig/apps/window-managment/setting-window-properties.md#set-app-name).&#x20;

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

})
```

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

```jsx
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.&#x20;

To write a file to the `path`.

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

Read `data` from file at `path`

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

### Normalize File paths

`fig.normalizeFilepath`

```javascript
fig.normalizeFilePath(`${fig.env.PWD}/..`, (normalized) => { 
    console.log(normalized) 
})
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://fig.gitbook.io/fig/apps/key-concepts/saving-data.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
