differentiate creation, renaming and updating content of files with node

这一生的挚爱 提交于 2020-01-06 06:42:26

问题


I need to perform an action when files from a directory are created, renamed, or deleted. But not when content inside a file changes.

how can i do this with native node.js?

I tried

const fs = require('fs')
const path = require('path')
const ROOT_PATH = path.resolve('components')

fs.watch(ROOT_PATH, (eventType, filename) => {
  console.log(eventType)
})

according to the documentation, eventType should return rename for creating, renaming, deleting.

And change when the content changes.

but the problem is that sometimes when I change the contents of some file inside the components directory, eventType returnsrename when should it be change....

so I am not able to differentiate creation, rename, delete fromcontent change

can someone help me with a native node solution with the fs module?

来源:https://stackoverflow.com/questions/56926903/differentiate-creation-renaming-and-updating-content-of-files-with-node

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!