Skip to content
Advertisement

How to connect to index.php file with Express and Node.js

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:

JavaScript

This is my index.html:

JavaScript

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?

Advertisement

Answer

Ciao Michele,

you can try with a PHP interpreter for NodeJS, it is called php-express. So, first of all need to install it with:

JavaScript

than your project structure must be:

JavaScript

index.js

JavaScript
  • in index.html need to append href attribute to window.location

example of your index.html

JavaScript

than an example of your index.php file

JavaScript

as finally run your express web server with:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement