File tree Expand file tree Collapse file tree 3 files changed +60
-0
lines changed Expand file tree Collapse file tree 3 files changed +60
-0
lines changed Original file line number Diff line number Diff line change 1+ <!doctype html>
2+ < html >
3+ < head >
4+
5+ < title > Anbothger Page</ title >
6+
7+ </ head >
8+ < body >
9+
10+ < h1 > Another Page</ h1 >
11+
12+ < p > This is a second page in the basic Node.js website.</ p >
13+
14+ < a href ="/index.html "> Back to the Home Page</ a >
15+
16+ </ body >
17+ </ html >
Original file line number Diff line number Diff line change 1+ var http = require ( 'http' ) ;
2+ var url = require ( 'url' ) ;
3+ var fs = require ( 'fs' ) ;
4+
5+ http . createServer ( function ( req , res ) {
6+
7+ var q = url . parse ( req . url , true ) ;
8+
9+ var filename = "." + q . pathname ;
10+
11+ fs . readFile ( filename , function ( err , data ) {
12+
13+ if ( err ) {
14+
15+ res . writeHead ( 404 , { 'Content-Type' : 'text/html' } ) ;
16+ return res . end ( "404 Not Found" ) ;
17+
18+ }
19+
20+ res . writeHead ( 200 , { 'Content-Type' : 'text/html' } ) ;
21+ res . write ( data ) ;
22+ return res . end ( ) ;
23+
24+ } ) ;
25+
26+ } ) . listen ( 8080 ) ;
Original file line number Diff line number Diff line change 1+ <!doctype html>
2+ < html >
3+ < head >
4+
5+ < title > My Node.js Website</ title >
6+
7+ </ head >
8+ < body >
9+
10+ < h1 > My Node.js Website</ h1 >
11+
12+ < p > This is a basic website using Node.js and the build in http and fs modules.</ p >
13+
14+ < a href ="/another-page.html "> Another Page</ a >
15+
16+ </ body >
17+ </ html >
You can’t perform that action at this time.
0 commit comments