How do I delete a file with node.js?
http://nodejs.org/api/fs.html#fs_fs_rename_oldpath_newpath_callback
I don't see a remove command?
In Node. js, you can use the fs. unlink() method provided by the built-in fs module to delete a file from the local file system.
unlink() method is used to remove a file or symbolic link from the filesystem.
You can't delete a file when running JavaScript from the browser, but you can do it when running JavaScript from a server environment like NodeJS. When you need to delete a file using NodeJS, You can use the fs. unlink() or fs.
I think you want to use fs.unlink.
More info on fs can be found here.
You can call fs.unlink(path, callback) for Asynchronous unlink(2) or fs.unlinkSync(path) for Synchronous unlink(2).
Where path is file-path which you want to remove.
For example we want to remove discovery.docx file from c:/book directory. So my file-path is c:/book/discovery.docx. So code for removing that file will be,
var fs = require('fs'); var filePath = 'c:/book/discovery.docx'; fs.unlinkSync(filePath);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With