-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3.js
40 lines (35 loc) · 935 Bytes
/
3.js
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
38
39
40
/**
* Simple Node.js http server
*that reads index.html from the file system.
*/
var http = require('http'),
fs = require('fs'),
path = require('path');
var app = http.createServer(function(req, res) {
var index = path.join(__dirname, 'index.html');
if (req.url == '/' || req.url == '/index.html') {
fs.readFile(index, function(err, data) {
if (err) {
console.error(err);
res.writeHead(500, {
'Content-Type': 'text/html'
});
res.end('500 server error');
} else {
res.writeHead(200, {
'Content-Type': 'text/html'
});
res.end(data);
}
});
} else {
console.log('resource not found: ' + req.url);
res.writeHead(404, {
'Content-Type': 'text/html'
});
res.end('<html> <body> 404 not found </body>');
}
});
//listen on localhost:3000
app.listen(3000, 'localhost');
console.log('server app running at localhost: 3000');