This article mainly introduces node. fs. the unlink method is described in this article. unlink method description, syntax, receive parameters, use instances, and implement Source Code. For more information, see
Method description:
Delete a file.
Syntax:
The Code is as follows:
Fs. unlink (path, [callback (err)])
Because this method belongs to the fs module, we need to introduce the fs module (var fs = require ("fs") before use "))
Receiving parameters:
Path file path
Callback, passing an exception parameter err.
Example:
The Code is as follows:
Var fs = require ('fs ');
Var filepath = '126.txt ';
Fs. unlink (filepath, function (err ){
If (err ){
Throw err;
}
Console. log ('file: '+ filepath +' deleted successfully! ');
})
Source code:
The Code is as follows:
Fs. unlink = function (path, callback ){
Callback = makeCallback (callback );
If (! NullCheck (path, callback) return;
Binding. unlink (pathModule. _ makeLong (path), callback );
};