write-echo.js 414 Bytes
Newer Older
Caleb C. Sander's avatar
Caleb C. Sander committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Import Node.js's 'fs' module
const fs = require('fs')

// Write 'hello, world' to the file
fs.writeFile('something.txt', 'hello, world', (err) => {
  if (err) throw err

  // Now read the file; it should contain 'hello, world' now.
  // 'utf8' indicates that the file is a text file encoded in UTF-8.
  fs.readFile('something.txt', 'utf8', (err, data) => {
    if (err) throw err

    console.log(data)
  })
})