forked from paulnguyen/code
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path11.httpserver.js
More file actions
37 lines (26 loc) · 728 Bytes
/
11.httpserver.js
File metadata and controls
37 lines (26 loc) · 728 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
https://nodejs.org/api/http.html
node 11.httpserver.js 8080
> HTTP Server Started on 8080
curl localhost:8080
> <h1>Hello World!</h1>
**/
var http = require('http') ;
var fs = require('fs') ;
var port = process.argv[2];
var server = http.createServer(
function (request, response) {
body = fs.readFileSync('11.index.html');
response.setHeader('Content-Type', 'text/html');
response.writeHead(200);
response.end( body );
}
)
server.listen(port) ;
console.log( `HTTP Server Started on ${port}\n` ) ;
/** Alternative:
http.createServer(function (req, res) {
res.writeHead(200, { 'content-type' : 'text/plain' });
fs.createReadStream( "11.index.html" ).pipe(res) ;
}).listen(8080);
**/