-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile.js
25 lines (24 loc) · 852 Bytes
/
file.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Include http module,
var http = require("http"),
// And mysql module you've just installed.
fs = require("fs");
// Create the http server.
http.createServer(function (request, response) {
// Attach listener on end event.
request.on("end", function () {
// Read the file.
fs.readFile("test.txt", 'utf-8', function (error, data) {
// Write headers.
response.writeHead(200, {
'Content-Type': 'text/plain'
});
// Increment the number obtained from file.
data = parseInt(data) + 1;
// Write incremented number to file.
fs.writeFile('test.txt', data);
// End response with some nice message.
response.end('This page was refreshed ' + data + ' times!');
});
});
// Listen on the 8080 port.
}).listen(8080);