HTML and CSS Reference
In-Depth Information
In this section you'll create, in four steps, a static file and serve it with Node:
• Step 1: Create a static file.
• Step 2: Load a file from a disk.
• Step 3: Send the file to the browser.
• Step 4: Run the application.
The end result will look identical to what you achieved in the previous section, but the ar-
chitecture will be improved because your display rendering is separated from your applic-
ation logic.
Step 1: Create a static file
The next listing is a simple index.html file—place it in a new working directory.
Listing E.2. A static index.html file
<!DOCTYPE html>
<title> Hello </title>
Hello world
Step 2: Load a file from a disk
Now that you have a static HTML file, you need to load it from a disk. Node has a built-in
module for reading files from a disk called fs . You can use the fs.readFile() method
to load a file. Create a new app.js file in your working directory and add the code from the
following listing.
Search WWH ::

Custom Search