Skip to content

Commit e9657ad

Browse files
committed
Simple server example
1 parent bb8826b commit e9657ad

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# node-scripts
2-
lolzz
2+
3+
Snippets of node js code.

server.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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...");

0 commit comments

Comments
 (0)