Reputation: 11
I was reading this Node.js In Action and there's this index.html
which references socket.io.js
from node_modules
folder (I believe).
How does the following script tag resolves the path to the socket.io.js
when the node_modules
folder is one directory up from where the index.html
resides?
The script tag:
<script src="/socket.io/socket.io.js" type="text/javascript"></script>
Upvotes: 1
Views: 722
Reputation: 850
When you include a module in your file, node first looks for the module in node_modules
folder in current directory. If it does not find it there then it moves to parent directory and looks for the module in node_modules
present in that directory, and it keeps moving up until it finds the required module.
Upvotes: 1
Reputation: 851
Socket.io reads the content of the socket.io-client/socket.io.js
file into a variable.
Socket.io has access to your app's http server, it then listens to requests that would match the URL of something like '/socket.io/socket.io.js' and responds with the contents of that variable above
You can see this in the socket.io source code:
Upvotes: 0