'nodejs web.js' works, 'foreman start' doesn't

I am developing a website, which I want to deploy on localserver/heroku/aws

On localserver and aws, when calling 'nodejs web.js' port 3000 works find.

When doing 'foreman start' it gives the feedback of listening to port 3000, but the browser doesn't show the site. Not on aws, and not on a localserver.

Of course, I got nothing working on heroku yet.

Note: '/public' dir was replaced with '/assets'.

web.js

var http = require("http"),
// utilities for working with file paths
path = require("path"),
// utilities for accessing the file system
fs = require("fs"),
extensions = {
    ".html": "text/html",
    ".css": "text/css",
    ".js": "application/javascript",
    ".png": "image/png",
    ".gif": "image/gif",
    ".jpg": "image/jpeg",
    ".ttf": "font/truetype",
    ".otf": "font/opentype",
    ".woff": "application/x-font-woff"
};


http.createServer(function(req, res) {

// look for a filename in the URL, default to index.html
var filename = path.basename(req.url) || "index.html",
    ext = path.extname(filename),
    dir = path.dirname(req.url).substring(1),
// __dirname is a built-in variable containing the path where the code is running
    localPath = __dirname + "/assets/";
if (extensions[ext]) {
    localPath += (dir ? dir + "/" : "") + filename;
    fs.exists(localPath, function(exists) {
        if (exists) {
            getFile(localPath, extensions[ext], res);
        } else {
            res.writeHead(404);
            res.end();
        }
    });
}

function getFile(localPath, mimeType, res) {
    fs.readFile(localPath, function(err, contents) {
        if (!err) {
            res.writeHead(200, {
                "Content-Type": mimeType,
                "Content-Length": contents.length
            });
            res.end(contents);
        } else {
            res.writeHead(500);
            res.end();
        }
    });
}


}).listen(process.env.PORT || 3000, function() {
    console.log("listening on 3000");
});

Procfile

web: nodejs web.js

package.json

{
"name": "myapp",
"version": "0.0.1",
"description": "web developer",
"main": "web.js",
"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
    "express": "2.5.x"
},
"engines": {
    "node": "0.8.x",
    "npm": "1.1.x"
},
"repository": {
    "type": "git",
    "url": "https://github.com/heroku/node-js-sample"
},
"keywords": [
    "node",
    "heroku"
]

By default it is:

node web.js

Unless you specify in the package.json file under start{} otherwise.

Edit Procfile

web: node web.js

That should do it. :)

Lets try to debug it, please mention the following test results:

  1. make sure node is listening to port 3000:

    netstat -lnW | grep :3000
    

    success case: prints the listener information

  2. then try to connect to port 3000:

    telnet localhost 3000
    

    success case: prints "Connected to localhost", type something and hit the enter, you should get a "400 Bad Request" error page

  3. add a debug message to the handler function before the conditional part, something like:

    http.createServer(function(req, res) {
      console.log(path.basename(req.url) || "no specific page");
    
    ...}
    

    success case: obvious