I am building a website which uses Apache + PHP on port 80 for the frontend, and Node.js + Socket.IO for dynamic updates on port 3000. There are quite a few shared Javascript resources between the two and I'd like to know how I can share them.
Here's my project layout:
project/
www/ // Apache DocumentRoot
index.php
js/ // Javascript files for the HTML pages
css/
app/
App.php // All the PHP files
node/
node_modules/ // Node modules installed by NPM
app.js // Node.js application
When my PHP application generates HTML code, it needs to put some <script> tags in <head> for things like underscore.js, backbone.js, socket.io.js, etcerea. But these scripts are all somewhere in de node_modules directory.
I have seen various examples but most use Node.js to serve the HTML page as well (usually using the express framework). So, they generate script includes like /socket.io/socket.io.js. But in my case I have two servers running on two ports.
So, how can I load the proper Javascript files without manually copying things from the node_modules directory to the js directory under the DocumentRoot?