aaa.txt:123;
server.js:
读文件:
/**
* Created by ArcherFant on 2017/9/17.
*/
const fs=require('fs');
fs.readFile('aaa.txt',function(err,data){
if(err){
console.log('读取失败');
}else{
console.log(data.toString());
}
})
/**
* Created by ArcherFant on 2017/9/17.
*/
const fs=require('fs');
const http=require('http');
var server=http.createServer(function(req,res){
var file_name='./www'+req.url;
fs.readFile(file_name,function(err,data){
if(err){
console.log('bbb');
res.write('404');
}
else{
console.log('bbbb');
res.write(data);
}
res.end();
});
console.log('aaa');
});
server.listen(8080);
写文件:
/** * Created by ArcherFant on 2017/9/17. */ const fs=require('fs'); fs.writeFile('bbb.txt','jdsggyu',function(err){ console.log(err); })