How does Node serve client .js files?


For example, let's say we're trying to use

In the html file served to the client, we include the following in the file.

<script src="/"></script>

So two questions regarding this:

  1. When the html file gets served to the client, it loads the resource (http://localhost:8080/ without triggering the requestHandler in server.js (I have a log statement for any request that hits localhost:8080). How does this resource load on the client without triggering the requestHandler?

  2. Where does Node find the resource that is required by the client?

Problem courtesy of: Mark


Assuming you are using one of the basic examples, this is because overrides your handle with it's own and won't run your handler if the request is for something that manages.

When you call .listen(app) or .listen(80) it will set up all of the handlers it needs to process data and serve the client JS file.

Solution courtesy of: loganfsmyth


There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.