java 令牌作用_SyntaxError:意外的令牌功能

通过Node运行聊天应用程序,并在运行server.js时出现以下错误:function serveStatic(response,cache,absPath)^^^^^^^^ SyntaxError:Object.exports上的意外令牌函数 . 在Module.load(module.js)的Object.Module._extensions..js(module.js:580:10)的Module._compile(module.js:543:28)的runInThisContext(vm.js:73:16) 488:32)在运行时在Module.runMain(module.js:605:10)的Function.Module._load(module.js:439:3)的tryModuleLoad(module.js:447:12)处(bootstrap_node.js: 418:7)在bootstrap_node.js启动时(bootstrap_node.js:139:9):533:3

这是Server.js代码:

var http=require('http');

var fs=require('fs');

var path=require('path');

var path= require('mime');

var cache={};

var server=http.createServer(function(request,response)

{

var filePath=false;

if(request.url=='/')

{

filePath= public/index.html;

}

else

{

'public' + request.url;

}

var absPath= './'+filePath;

serveStatic(response,cache,absPath);

});

server.listen(3000,function()

{

console.log('Server listening to the port :3000');

});

function send404 (response )

{

response.writeHead(404,{'Content-Type' :'text/plain'});

response.write('Error 404: resource not found');

response.end();

}

function sendFile(response,filePath,fileContents)

{

response.wrieHead(200,

{"content-type":mime.lookup(filePath)})

};

response.end(fileContents);

}

function serveStatic(response,cache,absPath)

{

if(cache[absPath])

{

sendFile(response,absPath,cache[absPath]);

}

else

{

if(fs.exists(absPath, 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);

}

});

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值