Ask coding questions

← Back to all posts
Ask || Server To Index
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

Voters
GatewayDuckYT
Comments
hotnewtop
tussiez

server file

The website:
HTML

JavaScript:

SixBeeps

Depends on what kind of information, what method of comms, etc.
If you want asynchronous information transmission and you're using socket.io, you can use the emit() function. See this. Otherwise, if you're looking for more of a synchronous method of info transmission, you can make an HTTP GET request with XMLHttpRequest and return the info when the server gets that request.

GatewayDuckYT

@SixBeeps This Dont Work

index.ejs

server.js

SameeraMurthy

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

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

GatewayDuckYT

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

SameeraMurthy

@GatewayDuckYT you can send info with socketio like this

and in the front end do:

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