const app = require('express')() const server = require('http').createServer(app) const io = require('socket.io')(server) const port = || 8080 app.get('/', function(req, res) ) Īfter logging messages on connections and disconnections, the client script must be included to initialize the socket object so that clients can create connections as needed. If all these steps are done, let’s create a simple file called server.js. Instead of using the node command, you can use nodemon to avoid restarting the server whenever a file changes. Now we are ready to install Express and Socket.io npm i -save express socket.io node -version npm -versionĪfter making sure that Node and npm are downloaded, create a new file and set up the npm package to create a package.json configuration file. You can run the following lines in your terminal to confirm that node and npm are installed. You will need Node and npm installed before you can start creating apps with Socket.IO.
0 Comments
Leave a Reply. |