Calling nodejs scripts from the command line does not work

Problem

This is what my file test.js contains:

console.log("Hello Stackoverflow");

This is what happens when I attempt to run it:

$ ls
test.js
$ node test.js
$ node test
$ node "test"
$ node "test.js"
$ node --debug test.js
debugger listening on port 5858
$ node --debug test
debugger listening on port 5858
$ 

Notice that it never works :( I can run just "node" and evaluate javascript statements line by line but whenever I try to run a script as above it does not work.

I'm running OS X 10.8 and a brand new installation of nodejs.

Problem courtesy of: Macmee

Solution

The solution to my problem was to uninstall node using:

sudo rm -rf /usr/local/{bin/{node,npm},lib/node_modules/npm,lib/node,share/man/*/node.*}

I then installed brew on my mac:

ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"

And then I did

brew doctor

I fixed the issues it told me to fix from that, and then I did

brew install node

I then restarted terminal, and node was working.

Solution courtesy of: Macmee

Discussion

There is currently no discussion for this recipe.

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