File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed
Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change 11# node-scripts
2- lolzz
2+
3+ Snippets of node js code.
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+
6+ http . createServer ( function ( req , res ) {
7+ var path = url . parse ( req . url ) . pathname ;
8+ path = path . substr ( 1 ) ;
9+ console . log ( "pathname requested: " + path ) ;
10+ fs . readFile ( path , function ( err , data ) {
11+ if ( err )
12+ {
13+ console . log ( err . stack ) ;
14+ res . writeHead ( 404 , { 'Content-Type' :'text/html' } ) ;
15+ }
16+ else
17+ {
18+ console . log ( data . toString ( ) ) ;
19+ res . writeHead ( 200 , { 'Content-Type' :'text/html' } ) ;
20+ // res.writeHead(path);
21+ res . write ( data . toString ( ) ) ;
22+ }
23+ res . end ( ) ;
24+
25+ } )
26+
27+ } ) . listen ( 1234 ) ;
28+
29+ console . log ( "Server @ 1234..." ) ;
You can’t perform that action at this time.
0 commit comments