1

I downloaded the Angular project angular-seed, and was using the node web-server.js file they provided to run my code.

I already built out enough functionality that it would be non-trivial to switch to another project and re-do the URL handling already managed in web-server.js.

I want to add socket.io to my stack. However, the way socket.io is (by default) added to the client stack is a line that looks like this:

<script src="/socket.io/socket.io.js"></script>

Because of the web-server.js URL rewrites, this doesn't work. What do I do?

I already have installed node.js, npm, and socket.io

1 Answer 1

2

socket.io.js on client code is served dynamically by node (it's not a resource). However, this web-server does url rewriting, so you can't use it as normal:

<script src="/socket.io/socket.io.js"></script>

but instead you need to serve it like so:

<script src="http://nodeJS_server:port/socket.io/socket.io.js"></script>

where, for testing, nodeJS_server is probably localhost

and port is what you define for socket.io, and not node itself. For example, in your dependencies at the top of web-server.js, if you added

io = require('socket.io').listen(8080),

That is creating a new server on port 8080 to handle your socket communication. So you would define your socket.io.js file in index.html as:

<script src="http://localhost:8080/socket.io/socket.io.js"></script>

Hope this saves someone else a bit of time.

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.