文件的增删该查
增
var fs = require ( 'fs' );fs.writeFile('路径','hello fs',function(error){ if( error ) throw error else{ console.log( '增加成功' );}})
改
var fs = require( ' fs ');fs.appendFile ( '路径',' HELLO FS ', 'utf8' ,function( error ){ if( error ) throw error else{ console.log( ' 修改成功 ' );}})
查
var fs = require( ' fs ');fs.readFile( ' 路径 ', ' utf8 ',functon(error,data){ if( error ) throw error console.log(data);})
删
var fs = require( 'fs' );fs.unlink( ' 路径 ',function(error){ if( error ) throw error console.log( '删除成功' );})
目录的增删该查
增
var fs = require( 'fs' );fs.mkdir( '路径',function( errror ){ if( error ) throw error console.log('目录增加成功');})
改
var fs = require ( ' fs ');fs.rename('旧路径',‘新路径’,function( error ){ if( error ) throw error console.log( '修改成功' );})
查
for(var i = 0; i<10; i++){ fs.writeFile('./fs/第${i}.txt',i,function(){ console.log('第${i}个创建成功'); })}var fs = require ( ' fs ' );fs.readdir( '路径',function(error,data){ if( error ) throw error console.log( data )})
events
var Events = require( 'enents' ) ;class MyEvents extends Events{};var MyEvents = new MyEvents();//console.log( Myevents );声名事件MyEvents.on('a',function(){ console.log( hello events );})触发事件MyEvents.emit('a');