fs.prepend
fs.prepend
Function
Write the content to the beginning of the file.
Syntax
fs(path).prepend(content)
Parameters
| Parameters | Type | Required | Default value | Description |
|---|---|---|---|---|
| content | Any | No | '' | Content to prepend; arrays and objects write JSON strings. |
Return value
| Type | Description |
|---|---|
| Int | Returns the total number of bytes of the new file contents. |
Example
file = fs('docs-prepend.txt') file.write('Lang') result = file.prepend('BT ') // Output: 7 print result
Notes
- When the file exists, the old content will be read first and then written back as a whole.