Wednesday, July 16, 2014

Node.js example - retrieve dir and base using path module

The "path" module contains utilities for handling and transforming file paths.

Example to using path module:

var http = require("http");
var path = require("path");
 
http.createServer(function(request, response){
 
 var dirname = path.dirname(decodeURI(request.url));
 var basename = path.basename(decodeURI(request.url));
 
 response.writeHead(200, {"Content-Type": "text/plain"});
 response.write("Hello World! \n");
 response.write("from mobile-web-app.blogspot.com \n");
 
 response.write("dirname: " + dirname + "\n");
 response.write("basename: " + basename + "\n");
 
 response.end();
}).listen(8888);


No comments:

Post a Comment