node.js remove file

前端 未结 17 1510
误落风尘
误落风尘 2020-12-07 06:54

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?

17条回答
  •  生来不讨喜
    2020-12-07 07:29

    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);
    

提交回复
热议问题