Database Reference
In-Depth Information
// Prints "This function can only be used internally"
mod.notExported();
// Throws an exception "Object #<Object> has no method
'notExported'"
Returning a module-level function requires overriding the exports object
itself by assigning a function to module.exports :
exports = module.exports = function() {
//Do something here
};
Because functions are objects, other exports can continue to be added as
above.
Developing Node Web Applications
Outofthebox,nodehasAPIsforcreatingandusingwebapplications. There
isalow-level http (or https )librarythatcanbeusedtowriteaverysimple
web server. There are even built-in APIs for common web server functions
like parsing query strings, encoding and decoding data and so on.
Implementing a basic server only takes a few lines of code:
var http = require('http')
, url = require('url')
, querystring = require('querystring')
;
http.createServer(function(request,response) {
var query =
querystring.parse(url.parse(request.url).query || "");
response.writeHead(200,{'content-type':"text/
plain"});
response.end("Hello "+(query.name ||
"Anonymous")+"\n");
}).listen(3000);
Of course, this is a very low-level way to work and does not have any of the
conveniences of a modern web framework. There are a variety of options
to provide these higher-level interfaces. One of the most popular is the
Search WWH ::




Custom Search