why it is not calling a.html

Problem

 var http = require('http');
 http.createServer(function (req, res) {

if (req.url == '/') 
{
    req.url += "a.html";
    //facebookAPI(req,res);
}

    }).listen(1337);

when I typed the address in the browser it was not calling that url. Any thought Thank you.

Problem courtesy of: draford

Solution

Here is how you could serve that file. This is untested!

var http = require('http');
var fs = require('fs');
http.createServer(function (req, res) {
    if (req.url == '/') 
    {
        fs.readFile('a.html', 'utf8', function(err, data) {
          if(err) {
            res.end('Error Loading File');
            return;
          }

          res.end(data);
        });
    } else {
        res.writeHead(404, {'Content-Type': 'text/plain'});
        res.end('file not found');
    }
}).listen(1337);

There are better ways to accomplish the same thing, but this should get you started.

Solution courtesy of: Timothy Strimple

Discussion

There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.