HTML and CSS Reference
In-Depth Information
E.1.4. Routing: serving different files for different URLs
Routing is the matching up of the URL requested by the browser with the appropriate re-
sponse from the server. The following listing demonstrates a simple approach.
Listing E.7. Simple routing app.js example
The example increments the variable only once for every page reload in Chrome, because
the index.html is sent only to explicit requests for it or for the root document.
In this section, we've provided a low-level understanding of how Node handles web ap-
plications. In real life, you don't want to spend hours figuring out how to do things such
as sending each individual file to your users, or slicing up your data to fit into WebSocket
frames, or keeping up with all the changes in the specification. To avoid repeatedly doing
the boring stuff in Node.js, you need more modules. But the modules you'll need aren't
included as standard with Node like http and fs that you've already used. In the next
section, you'll learn how to go above and beyond the standard set of modules by down-
loading third-party modules using the Node Package Manager (NPM).
Search WWH ::




Custom Search