嗨我有一点问题,控制台发给我这个错误:ErrorType:undefined不是函数,var server = http.createSever(函数(请求,reposne)。你能帮助我吗?这是我的第一篇帖子这个网站。 这是一个代码:
var http = require('http');
var fs = require('fs');
var path = require('path');
var mime = require('mime');
var cache = {};
function send404(response){
response.writeHead(404, {'Content-Type': 'text/plain'});
response.write('Błąd 404');
response.end();
}
function sendFile(response, filePath, fileContent){
response.writeHead(
200,
{"content-type": mime.lookup(path.basename(filePath))}
);
response.end(fileContent);
}
function serverStatic(response, cache, absPath){
if(cache[absPath]){
sendFile(response, absPath, cache[absPath]);
}
else {
fs.exists(abs.Path, function(exists){
if(exists){
fs.readFile(absPath, function(err, data){
if(err){
send404(response);
}
else {
cache[absPath] = data;
sendFile(response, absPath, data);
}
});
}
else {
send404(response);
}
});
}
}
var server = http.createSever(function(request, reposne){
var filePath = false;
if(request.url == '/'){
filePath = 'public/index.html';
}
else {
filePath = 'public' + request.url;
}
var absPath = './'+filePath;
serverStatic(response, cache, absPath);
});
server.listen(3000, function(){
console.log("port 3000");
});
答案 0 :(得分:0)
它是createServer
,而不是createSever
(请注意r
之前的v
)。