Socket.IO accepts non-existing src tag?

I'm doing some 'Get started thing' on Socket.IO and I noticed there was a step where I had to add the socket.io.js script to the HTML page. It said the following:

/socket.io/socket.io.js

In in my folders however, socket.io.js is at the following path:

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

There location socket.io doesn't exist in the root of the directory. Why exactly is it then that the first path works but the second doesn't?

Upvotes: 1

Views: 36

Answers (1)

jfriend00
jfriend00

Reputation: 707976

The server-side socket.io code installs a nodejs route handler for /socket.io/socket.io.js so that it can serve the socket.io.js file from its real location when /socket.io/socket.io.js is requested by a browser.

Remember, nodejs does not serve any local files automatically. It only serves files that are processed by some sort of route or handler. There is no route for node_modules/socket.io/node_modules/socket.io-client/socket.io.js so if a browser requests that, it won't serve anything.

Upvotes: 1

Related Questions