What 1.Node.js that?
(1) Nodejs is a technology to develop high-performance servers and birth
(2) Simply put Node.js is running on the server side JavaScript , based on the V8 were running
(3) Node.js uses an event-driven, non-blocking I / O model, it lightweight and efficient .
2.Node.js the File module
1. The intake module
1 var fs = require("fs");
2. Operation Folder
2.1 Create a folder
// Create a folder -fs.mkdir fs.mkdir (path [, Options], callback) // Create a folder test fs.mkdir("./test", function (err) { if (err) { return console.error("创建失败:", err); } console.log ( "folder is created." ); });
2.2 reading folder
// read the folder fs.readdir (path, callback) // read the current test file in the directory folder contents fs.readdir ( "./ test", function (ERR, Files) { IF (ERR) { return Console .error ( "failed to read the folder:" , ERR); } files.forEach( function (file){ console.log( file ); }); });
3.3 delete folders
// delete folders fs.rmdir (path, callback) fs.rmdir("./test",function(err){ if (err) { return console.error("删除失败:",err); } console.log ( "deleted successfully" ); });
3.4 write (create) file
fs.writeFile(filename,data,callback) filename: write to the file name data: Data written to the file (String | Buffer) callback (err): Error Message Parameters
3.5 reads the contents of the file