![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
@dmail/filesystem-watch
Advanced tools
[![npm package](https://img.shields.io/npm/v/@dmail/filesystem-watch.svg)](https://www.npmjs.com/package/@dmail/filesystem-watch) [![build](https://travis-ci.com/dmail/filesystem-watch.svg?branch=master)](http://travis-ci.com/dmail/filesystem-watch) [![co
Watch changes on your filesystem, either in a folder or on a specific file.
@dmail/filesystem-watch
has the following exports.
registerFolderLifecycle
registerFileLifecycle
registerFolderLifecycle
exampleregisterFolderLifecycle
is meant to be used when you need to something in sync with a given folder contents.
import { registerFolderLifecycle } from "@dmail/filesystem-watch"
const folderContentMap = {}
registerFolderLifecycle("/Users/you/folder", {
added: ({ relativePath, type ) => {
folderContentMap[relativePath] = type
},
removed: ({ relativePath }) => {
delete folderContentMap[relativePath]
},
})
— see registerFolderLifecycle
documentation
registerFileLifecycle
exampleregisterFileLifecycle
is meant to be used when you need to do something in sync with a given file content.
import { readFileSync } from "fs"
import { registerFileLifecycle } from "@dmail/filesystem-watch"
const path = "/Users/you/folder/config.js"
let currentConfig = null
registerFileLifecycle(path, {
added: () => {
currentConfig = JSON.parse(String(readFileSync(path)))
},
updated: () => {
currentConfig = JSON.parse(String(readFileSync(path)))
},
removed: () => {
currentConfig = null
},
})
— see registerFileLifecycle
documentation
npm install @dmail/filesystem-watch@2.4.0
I needed something capable to watch file changes on the filesystem.
The documentation of fs.watch makes it clear that you cannot really use it directly because it has several limitations specific to the filesystem.
Then I tried chokidar, a wrapper around fs.watch. However I could not fully understand what chokidar was doing under the hood.
What I needed was small wrapper around fs.watch that do not shallow events sent by the operating system. Ultimately chokidar could maybe do what I need but it's a bit too big for my use case.
— see fs.watch documentation
— see chokidar on github
Everywhere:
change
as chunk gets written in the file.change
on folder when something inside folder changesOn mac:
rename
instead of change
when updating a fileOn linux:
On windows:
FAQs
[![npm package](https://img.shields.io/npm/v/@dmail/filesystem-watch.svg)](https://www.npmjs.com/package/@dmail/filesystem-watch) [![build](https://travis-ci.com/dmail/filesystem-watch.svg?branch=master)](http://travis-ci.com/dmail/filesystem-watch) [![co
We found that @dmail/filesystem-watch demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.