Tyler Durden Tyler Durden - 1 year ago 212
Javascript Question

Node npm - referencing three.js module on the front end

I'm currently using the node npm to manage dependencies like jquery on the front end. Using the following method.

Server (working)

app.use('/jquery', express.static(__dirname + '/node_modules/jquery/dist/'));

Client (working)

<script src="/jquery/jquery.js"></script>

This works, but I was hoping to be able to manage the dependency 'three.js' from the server side too. Something like...

Server (not working)

app.use('/three', express.static(__dirname + '/node_modules/three/dist/'));

Client (not working)

<script src="/three/three.js"></script>

Error ()

failed to load resource the server responded with a status of 404 (not found)

How can I find the directory structure of the npm module?

Answer Source

In the three.js project, the built files are located in the build directory, not the dist.

On the server, this should work:

app.use('/three', express.static(__dirname + '/node_modules/three/build/'));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download