- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttpserver.js
More file actions
Latest commit
25 lines (24 loc) · 834 Bytes
/
Copy pathhttpserver.js
File metadata and controls
25 lines (24 loc) · 834 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
varhttp=require("http");
varfs=require("fs");
varport=process.argv[2];
varfileToServe=process.argv[3];
// var server = http.createServer(function(request, response) {
// console.log("opening read stream with file location: " + fileToServe);
// var readStream = fs.createReadStream(fileToServe);
// readStream.on('error', function(message) {
// console.error("There was an error creating the read stream: " + message);
// });
// readStream.on('close', function() {
// });
// readStream.on('end', function() {
// response.end();
// });
// readStream.on('data', function(chunkOfData) {
// response.write(chunkOfData);
// });
// });
// server.listen(port);
varserver=http.createServer(function(request,response){
fs.createReadStream(fileToServe).pipe(response);
});
server.listen(port);