Node writeFile

fs exists mkdir writeFile appendFile

let fs = require('fs')
fs.exists('./output/result.txt', (exists) => {
  if (!exists) {
    fs.mkdir('./output', (err) => {
      if (err) throw err
    })
  } else {
    fs.writeFile('./output/result.txt', 'write data', () => {
      if (err) throw err
      console.log()
    })
    fs.appendFile('./output/result.txt', 'append data', (err) => {
      if (err) throw err
      console.log('The file has been saved!')
    })
  }
})

你可能感兴趣的:(Node writeFile)