1

I am trying to run a nodeJS test script with socket.io but the deployed script on my server causes an error if I am trying to include any javascript.

Just calling the HTML via nginx on my localhost does not throw any error.

this is my index.html:

<!DOCTYPE HTML>
<html>
<head>
    <meta charset="UTF-8" />
    <title>NodeJS Realtime Test</title>
    <script type="text/javascript" src="/client/app.js"></script>
</head>
<body>
    <p>Moin!</p>
</body>
</html>

and this is the content of the app.js:

console.log("test");

Chrome throws me this error:

Uncaught SyntaxError: Unexpected token < app.js:1

In Opera, the error is:

Syntax error at line 1 while loading: expected expression, got '<'  Linked script compilation   app.js

also, the debugger shows that the error occurs on char one of my index.html file. what am I missing here?

2
  • 1
    The error in Chrome is pointing to line 1 in app.js, not in index.html. Did you look what the file /client/app.js looks like by opening it in the browser (or using Chrome's dev tools)? Commented Jun 14, 2012 at 12:42
  • indeed. opening app.js on the server shows the content of index.html. so it is the server configuration that is causing the error. I took the one from the socket.io example. Commented Jun 14, 2012 at 12:46

1 Answer 1

1

Thanks to the comment of Jani Hartikainen I recognized that it was a misconfiguration of the nodeJS server.

The example I used served index.html on any request on the server. It works using this configuration: https://gist.github.com/701407

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.