jprichardson / node-fs-extra

Node.js: extra methods for the fs object like copy(), remove(), mkdirs()
MIT License
9.43k stars 775 forks source link

Missing touch to update atime/mtime of a file #1000

Closed nichtich closed 1 year ago

nichtich commented 1 year ago

I was missing touch and found it had been removed. To update the timestamp of a file, use this function:

async function touchFile(file) {          
  await fs.ensureFile(file)
  const time = new Date()
  return fs.utimes(file, time, time)
}