計數器程式碼:
var http = require('http');
var fs = require("fs"),
data = "count.txt",
count = 0,
encode ="utf8";
fs.readFile(data, encode, function(err, file) {
console.log(file);
count = file;
http.createServer(function (req, res) {
fs.writeFile("count.txt",count,function(){});
count++;
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello , you are the ' +count + "st guest~");
}).listen(1337, '127.0.0.1');
});
console.log('Server running at http://127.0.0.1:1337/');
var http = require('http');
var fs = require("fs"),
data = "count.txt",
count = 0,
encode ="utf8";
fs.readFile(data, encode, function(err, file) {
console.log(file);
count = file;
http.createServer(function (req, res) {
fs.writeFile("count.txt",count,function(){});
count++;
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello , you are the ' +count + "st guest~");
}).listen(1337, '127.0.0.1');
});
console.log('Server running at http://127.0.0.1:1337/');
留言
張貼留言