---
url: /process-functions/datasource-writeFile.md
description: Writes text or bytes to a file. Missing folders in the path are created.
---

# datasource.writeFile&#x20;

Writes text or bytes to a file. Missing folders in the path are created.

```js
datasource.writeFile(fileName, data, append)
```

## Parameters

| Parameter | Type | Description |
|---|---|---|
| `fileName` | `string` | The path of the file. |
| `data` | `string \| number[]` | The text to write, written as UTF-8, or an array of byte values from 0 to 255. |
| `append` | `boolean` | Optional. `true` to add to the end of the file instead of replacing it. Defaults to `false`. |

## Returns

`true` when the file was written, or `false` when the path is invalid.

## Examples

```js
// Write text to a new file
datasource.writeFile("output/report.txt", "Hello, World!");

// Append text to an existing file
datasource.writeFile("output/log.txt", "New log entry\n", true);

// Write binary data as an array of integers
const bytes = [72, 101, 108, 108, 111]; // "Hello" in ASCII
datasource.writeFile("output/data.bin", bytes);

// Write JSON data
const data = {
    name: "Budget Report",
    year: 2024,
    values: [100, 200, 300]
};
datasource.writeFile("output/report.json", JSON.stringify(data, null, 2));
```
