Implemented a simple web server

This commit is contained in:
Mattias Erming 2014-03-04 08:31:52 -08:00
parent 196f9aa551
commit e65c9130c0
5 changed files with 51 additions and 1 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules/

14
app.js
View File

@ -1 +1,13 @@
console.log("Hello, world."); var argv = require("commander")
.option("-p, --port <n>", "port to use", parseInt)
.parse(process.argv);
PORT = 80; // Default port.
if (argv.port) {
PORT = argv.port;
}
// Run the server!
var Server =
new (require("./lib/server.js"))()
.listen(PORT);

1
client/index.html Normal file
View File

@ -0,0 +1 @@
Hello, world.

30
lib/server.js Normal file
View File

@ -0,0 +1,30 @@
/**
* Module dependencies.
*/
var connect = require("connect");
/**
* Export module.
*/
module.exports = Server;
/**
* The Server class.
*
* @public
*/
function Server() {
/**
* Start the server.
*
* @public
*/
this.listen = function(port) {
connect().use(connect.static("client")).listen(port);
};
};

6
package.json Normal file
View File

@ -0,0 +1,6 @@
{
"dependencies": {
"connect": "2.13.0",
"commander": "2.1.0"
}
}