var html = "<!doctype html>" +
"<html><head><title>Hello world</title></head>" +
"<body><h1>Hello, world!</h1></body></html>";
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(html);
}).listen(1337, '127.0.0.1');
console.log(readx("data.txt"));
function readx( filename ){
var fs = require("fs");
var fileContent = "";
var stat = fs.statSync(filename);
var fd = fs.openSync(filename, "r");
var bytes = fs.readSync(fd, stat.size, 0, "ascii");
fileContent += bytes[0];
fs.closeSync(fd);
return fileContent;
};
最終更新:2015年11月10日 15:40