HTML and CSS Reference
In-Depth Information
Listing E.3. An app.js file that reads a file from a disk
Step 3: Send the file to the browser
After the readFile() function has completed, your callback function will execute; you
need to check that the file was read successfully and send it to the browser. You can use the
same http module methods from section E.1.1 to do this. Replace the comment in listing
E.3 with the code in the following listing.
Listing E.4. Sending the file to the browser in app.js
Step 4: Run the application
Just as in the last example, start your application from the command line:
node app.js
Point your browser at http://localhost:8080/ and check that you can see the Hello World
Serving static files isn't interesting in and of itself, but serving purely dynamic files, as in
section E.1.1 , isn't practical either; in a real application you don't want your web designers
Search WWH ::

Custom Search