Javascript NodeJS-SyntaxError:预期表达式,get'<';

Javascript NodeJS-SyntaxError:预期表达式,get'<';,javascript,node.js,Javascript,Node.js,我正在使用NodeJS和Socket.io。这是我的index.js var app = require('http').createServer(handler); var io = require('socket.io').listen(app); var fs = require('fs'); app.listen(3000); console.log("Listening on port 3000"); function handler

我正在使用NodeJS和Socket.io。这是我的index.js

    var app = require('http').createServer(handler);
    var io = require('socket.io').listen(app);
    var fs = require('fs');

    app.listen(3000);
    console.log("Listening on port 3000");

    function handler(req, res) {
      fs.readFile(__dirname + '/index.html', function( err, data ) {
        if( err ) {
          res.writeHead( 500 );
          return res.end('Error loading index.html');
        }

        res.writeHead( 200 );
        res.end( data );
      });
    }
这是我的index.html

<!DOCTYPE html>
<html>
<head>
    <script src="http://localhost:3000/socket.io/socket.io.js"></script>
    <title>Impact Game</title>
    <style type="text/css">
        html,body {
            background-color: #333;
            color: #fff;
            font-family: helvetica, arial, sans-serif;
            margin: 0;
            padding: 0;
            font-size: 12pt;
        }

        #canvas {
            position: absolute;
            left: 0;
            right: 0;
            top: 0;
            bottom: 0;
            margin: auto;
        }
    </style>

    <script src="lib/impact/impact.js"></script>
    <script src="lib/game/main.js"></script>
</head>
<body>
    <canvas id="canvas"></canvas>
</body>
</html>
看看这个:

无论浏览器要求什么,您都将提供
index.html

因此,当浏览器请求
lib/impact/impact.js
lib/impact/main.js
时,您会给它
index.html
的内容

您需要注意正在进行的操作(
req.url
)并返回正确的内容。

请看以下内容:

无论浏览器要求什么,您都将提供
index.html

因此,当浏览器请求
lib/impact/impact.js
lib/impact/main.js
时,您会给它
index.html
的内容



你需要注意正在发生什么(
req.url
)并返回正确的内容。

main.js的内容是什么??你在某个地方有一个错误括号…如果错误在
main.js
,那就是你应该发布的文件。你是否尝试运行main.js而不是index.js?当我在本地运行index.html时,它可以工作,所以文件应该是好的。但是当我通过Node执行此操作时,我得到了错误。
main.js
的内容是什么?您在某个地方有一个不正确的括号…如果错误在
main.js
中,那就是您应该发布的文件。您是否尝试运行main.js而不是index.js?当我在本地运行index.html时,它工作正常,因此该文件应该是好的。但是当我通过Node做的时候,我得到了一个错误。但是我不明白的是,我看的教程是这样的,它工作得非常好。我不打算费力地翻看所有的视频来找出它没有解释清楚的地方。我想象它根本没有从node.js加载索引页面,只是留下了一些样板。我从视频中下载了源代码,并尝试了同样的结果。这段视频已经有4年的历史了,那么这是否可以追溯到当时,但现在已经不再适用了?如果你将浏览器指向错误的URL,那么使用相同的源代码将不会有任何帮助,我认为你正在这样做。你是对的。我把url指向:8080,而不是wamp上文件所在的实际文件夹。但我不明白的是,我看的教程是这样的,它工作得非常好。我不打算费力地翻看所有的视频来找出它没有解释清楚的地方。我想象它根本没有从node.js加载索引页面,只是留下了一些样板。我从视频中下载了源代码,并尝试了同样的结果。这段视频已经有4年的历史了,那么这是否可以追溯到当时,但现在已经不再适用了?如果你将浏览器指向错误的URL,那么使用相同的源代码将不会有任何帮助,我认为你正在这样做。你是对的。我将url指向:8080,而不是wamp上文件所在的实际文件夹。
ig.module(
    'game.main'
)
.requires(
    'impact.game',
    'impact.font'
)
.defines(function(){

MyGame = ig.Game.extend({

    // Load a font
    font: new ig.Font( 'media/04b03.font.png' ),


    init: function() {
        // Initialize your game here; bind keys etc.
    },

    update: function() {
        // Update all entities and backgroundMaps
        this.parent();

        // Add your own, additional update code here
    },

    draw: function() {
        // Draw all entities and backgroundMaps
        this.parent();


        // Add your own drawing code here
        var x = ig.system.width/2,
            y = ig.system.height/2;

        this.font.draw( 'It Works!', x, y, ig.Font.ALIGN.CENTER );
    }
});


// Start the Game with 60fps, a resolution of 320x240, scaled
// up by a factor of 2
ig.main( '#canvas', MyGame, 60, 320, 240, 2 );

});
function handler(req, res) {
  fs.readFile(__dirname + '/index.html', function( err, data ) {