create-file.js 446 Bytes
const fs = require('fs')

// The arguments are the file to create and its initial contents.
// Run the program using node create-file.js FILENAME CONTENTS

fs.stat(process.argv[2], err => {
  if (err) {
    // File didn't exist, so create it
    fs.writeFile(process.argv[2], process.argv[3], err => {
      if (err) throw err

      console.log(`${process.argv[2]} created`)
    })
  }
  else console.log(`${process.argv[2]} already exists`)
})