Hardware Reference
In-Depth Information
res . end ();
});
}
function send404 ( res ) {
res . writeHead ( 404 );
res . write ( '404 - page not found' );
res . end ();
}
Creates the server. Whenever a browser requests a page from port 9090 , the func-
tion servepage is called.
Instructs the server to begin listening on port 9090 .
When servepage is called, req contains the path to the page being requested.
This code extracts the path to the page.
readFile reads the entire page being requested.
Be sure the page is there; if not, send the famous 404 error.
Write the page to the web browser.
Add the HTML in Example 6-1 to a file called test.html in the serverExample directory,
and then run this:
bone# cd serverExample
bone# chmod +x server.js
bone# ./server.js
Listening on 9090
 
 
 
 
 
Search WWH ::




Custom Search