Copyright 2025

The Valley of Code

A Flavio Copes project

Save some text to a file in Node.js
Save some text to a file in Node.js

So you want to save some text to a file using Node.js.

Super simple:

import fs from 'node:fs'

const text = 'yo'

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

Join my AI Workshop !

The Web Development BOOTCAMP cohort starts in February 2026