Javascript 链接index.html client.js和server.js

Javascript 链接index.html client.js和server.js,javascript,html,node.js,server,client,Javascript,Html,Node.js,Server,Client,我从Node.js开始,我的第一个程序中已经有一个问题。下面是我正在使用的代码。Index.html: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Random Temperatures</title> </head> <body> <input type="text" id="tb"

我从Node.js开始,我的第一个程序中已经有一个问题。下面是我正在使用的代码。Index.html:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Random Temperatures</title>
  </head>
  <body>
    <input type="text" id="tb" name="tb" />
    <input type="button" value="Random Number!" id="myButton" name="myButton"/>
    <script src="client.js"></script>
</body>
</html>
Server.js:

var app = require('http').createServer(response);
var fs = require('fs');
app.listen(8080);
console.log("App running…");
function response(req, res) {
    fs.readFile(__dirname + '/public/index.html',
    function (err, data) {
        if (err) {
            res.writeHead(500);
            return res.end('Failed to load file index.html');
        }
        res.writeHead(200);
        res.end(data);
    });
}
当我启动应用程序时,我进入浏览器,文本框和按钮出现。但在浏览器控制台中,我发现以下错误:


client.js:1未捕获的语法错误:意外标记浏览器请求
/client.js

服务器:

  • 获取请求
  • 运行
    响应
  • 读取
    index.html
  • 将其发送到浏览器

  • 由于
    index.html
    开头,我看到这个错误来自McAfee chrome扩展。它是否在匿名模式或其他浏览器中抛出相同的错误?我在Firefox中得到了这些错误:localhost:8080>>来自“”的脚本被加载,即使它的MIME类型(“”)不是有效的JavaScript MIME类型client.js:1>>SyntaxError:expected expression,get'但是你在我的代码中没有看到关于文件链接的任何错误吗?不,我觉得很好,肯定有什么小错误-(
    
    var app = require('http').createServer(response);
    var fs = require('fs');
    app.listen(8080);
    console.log("App running…");
    function response(req, res) {
        fs.readFile(__dirname + '/public/index.html',
        function (err, data) {
            if (err) {
                res.writeHead(500);
                return res.end('Failed to load file index.html');
            }
            res.writeHead(200);
            res.end(data);
        });
    }