December 2017
Intermediate to advanced
260 pages
7h 34m
English
We have already specified the dependency for Socket.IO in our package.json file. Look at this file. It has a dependency block, which is mentioned in the following code block:
"dependencies": { "ejs": "^2.5.7", "express": "^4.16.2", "kotlin": "^1.1.60", "socket.io": "^2.0.4" }
When we perform npm install, it basically downloads the socket-io.js file and keeps node_modules | socket.io inside.
We will add this JavaScript file to our index.ejs file.
There we can find the following mentioned <script> tag inside the <body> tag:
<script type="text/javascript" src="/socket.io/socket.io.js"> </script>
Also, initialize socket in the same index.js file like this:
<script> window.socket = io(); </script>
Read now
Unlock full access