2

I have a Node.js script that is running in a while (true) fashion and watches directories for certain files and removes them using unlink API:

fs.unlinkSync(path);

The files are not created by Node process, but as POSIX documentation about unlink says, files are not removed from disk until process is closed, thus lsof will list them as (deleted) and tied to node process.

My script is some kind of a "watchdog", so how would I go to removing those files and cleaning up disk space without restarting the Node process itself?

Thanks!

1 Answer 1

1

I would try child_process:

const { execSync } = require('child_process');
execSync(`rm ${filePath}`)
Sign up to request clarification or add additional context in comments.

1 Comment

This is exactly what I was thinking about, but seems a bit ugly to go there, but not sure if there's a better solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.