Skip to content
Ask || Server To Index
Profile icon
GatewayDuckYT

Ok So I want to send info from my server file to my index file (views/index.ejs) how do i do this btw i am useing socket.io allready

You are viewing a single comment. View All
Profile icon
tussiez

server file

const app = require('express')(); const http = require('http').createServer(app); const io = require('socket.io')(http); io.on('connection',function(socket){ socket.emit("Hey you","want a rick roll"); socket.emit("ok","hehe"); }); http.listen(3000,() => { console.log('Hai'); });

The website:
HTML

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

JavaScript:

const socket = io(); socket.on('Hey you',function(text){ alert(text); })