1

I need to create a function in NodeJS that permanently deletes temporary files (instead of just deleting the normal way and storing the deleted files in the trash). In fact, my program will create a lot of temporary files and eventually the server's hard drive will get full very fast.

2 Answers 2

3

fs.unlink(path, callback) will delete a file. As with all the fs methods, there's also the synchronous version, fs.unlinkSync(path).

https://nodejs.org/api/fs.html#fs_fs_unlink_path_callback

Sign up to request clarification or add additional context in comments.

Comments

0

Using unlink (with callback) /unlinkSync in fs module.

const fs = require('fs') fs.unlinkSync(__dirname + 'yourfile.name') 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.