Pancho Sanza Pancho Sanza - 3 years ago 126
Node.js Question

html5/nodejs/socketio developing while offline

node and socket.io.

all is working well until hooking up the

script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.3socket.io.js"></script


tag in the client html.
(this works fine while i have internet connection)

i have already tried some approaches to remedy this, they all just give me an
error:
"
Loading failed for the with source “http://localhost:2000/js/socket.io.js
"




i would like to develop an application, but not need to be hooked up to the internet while i develop it.




here is an idea of what my structure is looking like:

rootFolder:

-client

---img

---js//its here that ive tried storing various references to socket.io-client

---index.html //its into here that i am trying to inject the tag

-node_modules

---all the node modules, of particular interest: socket.io-client

-app.js

-package.json

i have been messing around trying to paste a copy of

./node_modules/socket.io-client/dist/socket.io.js

in various location relative to the app.js file, but with no luck.

thanks for the help

Answer Source

I am not sure I understand your question entirely. One thing I have noticed is that https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.3socket.io.js does not exist. From the structure you are showing, I think you will have to include the client socket.io file like this:

<script src="/node_modules/socket.io-client/dist/socket.io.js"></script>

The above is true only if your node_modules is inside your document root. Otherwise, you won't be able to access it.

Otherwise, if you are also hosting the socket.io server side, you can also try this in your html file:

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

since the server part of socket.io will expose the client file at that location according to the documentation on https://github.com/socketio/socket.io-client

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download