# Save some text to a file in Node.js

> Learn how to save text to a file in Node.js using the fs module and the writeFile method, with a simple example that handles errors and confirms when done.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2023-05-12 | Topics: [Node.js](https://flaviocopes.com/tags/node/) | Canonical: https://flaviocopes.com/save-some-text-to-a-file-in-nodejs/

So you want to save some text to a file using [Node.js](https://flaviocopes.com/nodejs/).

Super simple:

```javascript
import fs from 'node:fs'

const text = 'yo'

fs.writeFile('text.txt', text, (err) => {
  if (err) {
    console.error(err)
  }
  console.log('done')
})
```
