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
SameeraMurthy

You need to include socket.io in the client side (in index.ejs) and then do

const socket = io();

And make sure you have a socket.io server running.

Profile icon
GatewayDuckYT

@SameeraMurthy i do by from the server file how do i send info to the index file

Profile icon
SameeraMurthy

@GatewayDuckYT you can send info with socketio like this

io.on("connection", (socket) => { socket.emit("greeting", "Hello World"); })

and in the front end do:

socket.on("greeting", (data) => { alert(data) })

use this reference:
https://socket.io/docs/v3/emit-cheatsheet/