2

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?

1 Answer 1

3

There are 2 options:

  • Create a symlink (pointing from www/js to node_modules)
  • Create an Apache2 alias in you Apache configuration file (see here)

If you have access to your Apache2 configuration, the 2nd solution is probably the better one. When going for the symlink solution, make sure you double-check the ownership of the folders if you experience problems.

Sign up to request clarification or add additional context in comments.

1 Comment

I have accepted your answer as the correct one. In the end I chose a different solution though. I am now using Phing as a build system and I simply have it copy the files over to the correct directories (and minify them at the same time).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.