Skip to content

Commit

Permalink
Nodejs build-in module fs (read & write file)
Browse files Browse the repository at this point in the history
  • Loading branch information
lecaoquochung committed Jul 22, 2016
1 parent e8893a7 commit 5dee2e7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions example/data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello world!
13 changes: 13 additions & 0 deletions example/server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
var http = require('http');
var fs = require('fs');

http.createServer(function (req,res){
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n')
}).listen(9000,'127.0.0.1');
console.log('Server is running at http://127.0.0.1:9000');

// write file
fs.writeFile('data.txt', 'Hello world!', function (err){
if(err) {throw err;}
console.log('It is saved!');
});

// read file
fs.readFile('data.txt', function(err, data){
if(err) throw err;
console.log(data.toString());
});

0 comments on commit 5dee2e7

Please sign in to comment.