i am new to programming with javascript. and i picked angular + node.js for server side. i went through the angular tutorial and i have a few question regarding the web-server.js they gave. as the server part is not covered in the angular tutorial i have some questions:
the server is ran with this command line:
node ./scripts/web-server.js
the main function that is being executed is "main" it is done via: main(process.argv);
and the function is:
function main(argv) {
new HttpServer({
'GET': createServlet(StaticServlet),
'HEAD': createServlet(StaticServlet)
}).start(Number(argv[2]) || DEFAULT_PORT);
}
function HttpServer(handlers) {
this.handlers = handlers;
this.server = http.createServer(this.handleRequest_.bind(this));
}
function createServlet(Class) {
var servlet = new Class();
return servlet.handleRequest.bind(servlet);
}
function StaticServlet() {}
StaticServlet.MimeMap = {
'txt': 'text/plain',
'html': 'text/html',
'css': 'text/css',
'xml': 'application/xml',
'json': 'application/json',
'js': 'application/javascript',
'jpg': 'image/jpeg',
'jpeg': 'image/jpeg',
'gif': 'image/gif',
'png': 'image/png',
'svg': 'image/svg+xml'
};
my questions:
{ 'GET': createServlet(StaticServlet),
'HEAD': createServlet(StaticServlet)
}
i do not understand what these lines do. i assume this line creates an object, but the way that i know would be more like
{
GET: createServlet(StaticServlet),
HEAD: createServlet(StaticServlet)
}
what does the ' ' mean in those lines?
second question: what does these means?
.start(Number(argv[2]) || DEFAULT_PORT);
the .start functon is:
HttpServer.prototype.start = function(port) {
this.port = port;
this.server.listen(port);
util.puts('Http Server running at http://localhost:' + port + '/');
};
but i dont understand why is the || and argv[2] is actually null so why do we need to pass it.
third question: is regarding the creation of the StaticServlet.MimeMap. it is very similar to my first question i think. i do not understand the syntax here:
'txt': 'text/plain',.
what does it create?