Created
July 9, 2011 23:58
-
-
Save JakubOboza/1074073 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'), | |
util = require('util'), | |
url = require('url'); | |
function Counter(options) { | |
if (! (this instanceof arguments.callee)) { | |
return new arguments.callee(arguments); | |
} | |
this.settings = { | |
port: options.port | |
}; | |
this.init(); | |
}; | |
Counter.prototype.init = function() { | |
this.httpServer = this.createHTTPServer(); | |
this.httpServer.listen(this.settings.port); | |
util.log('Server started on PORT ' + this.settings.port); | |
}; | |
Counter.prototype.createHTTPServer = function() { | |
var server = http.createServer(function (req, res) { | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
var msg = util.inspect(req); | |
res.end( msg ); | |
console.log( msg ); | |
}); | |
return server; | |
}; | |
module.exports = Counter; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
. | |
├── lib | |
│ └── counter.js | |
├── public | |
│ ├── css | |
│ └── javascripts | |
├── server.js | |
└── vendor | |
5 directories, 2 files |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require.paths.unshift(__dirname + "/vendor"); | |
process.addListener('uncaughtException', function (err, stack) { | |
console.log('------------------------'); | |
console.log('Exception: ' + err); | |
console.log(err.stack); | |
console.log('------------------------'); | |
}); | |
var Counter = require('./lib/counter.js'); | |
console.log(Counter); | |
new Counter({ | |
port: 8000 | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment