I would like to create a real time application, but I am new to Node.js, Express and Socket.io.
I would like to connect with Express to a file called index.php.
Unfortunately I saw that Express connects by default to a file called index.html.
This is a part of my index.js file:
var express = require('express');
var socket = require('socket.io');
var app = express();
//App setup
var server = app.listen(4000, function() {
console.log('listening on requests on port 4000');
});
//Static files
app.use(express.static('public'));
//Socket setup
var io = socket(server);
This is my index.html:
<!DOCTYPE html>
<html>
<head>
<title>Socket Sender</title>
<script src="https://cdn.socket.io/3.1.1/socket.io.min.js" integrity="sha384-gDaozqUvc4HTgo8iZjwth73C6dDDeOJsAgpxBcMpZYztUfjHXpzrpdrHRdVp8ySO" crossorigin="anonymous"></script>
</head>
<body onload="redirect()">
<button id="send">Send</button>
<div id="table_container">
</div>
<script language=javascript>
function redirect(){
window.location = "index.php";
}
</script>
<!--<script src="/receiver.js"></script>-->
</body>
</html>
As you can see, I used a workaround to connect to a php file. So the index.html should redirect to index.php but for some reason the browser only downloads index.php and doesn't render that file.
Can help?