78

My node installation is at:

/usr/local/bin/node

and I've added the shebang:

#!/usr/local/bin/node

to the top of the file and given my node app file the permissions 755, but when I try to run:

> ./my-app

I get the old:

-bash: ./my-app: No such file or directory

What am I doing wrong?

just somebody
  • 18,602
  • 6
  • 51
  • 60
asking
  • 1,435
  • 3
  • 13
  • 21
  • 1
    my guess would be you're simply in a wrong directory. `ls -l ./my-app` should help. – just somebody Jun 16 '14 at 22:23
  • Whoops, actually, I guess it was because I had .js at the end of my file: removing the file type, from "my-app.js" to "my-app" allowed me to run it with `> ./my-app` – asking Jun 16 '14 at 22:47

1 Answers1

207

The node shebang is:

#!/usr/bin/env node

Not all systems place node in the same location, its possible that you have the location incorrectly. This will find them all.

Source

Also

Community
  • 1
  • 1
secretformula
  • 6,414
  • 3
  • 33
  • 56
  • @asking you should be able to have the `.js` part on there – secretformula Jun 16 '14 at 22:56
  • 1
    Hmm, then my head-scratching continues: My file was named "my-app.js", have the shebang `#!/usr/bin/env node` and node is on my path at "/usr/local/bin/node". As soon as I removed the ".js", the Mac OS considered it a binary, I suppose, and I was able to execute it as such. But now I'm confused again - par for the course. – asking Jun 16 '14 at 23:01
  • 2
    @secretformula for the record, it works on my macOS (Sierra) without extension, like it should. `chmod +x` was of course necessary. – Jeff Huijsmans Feb 01 '18 at 16:23
  • [This answer](https://stackoverflow.com/questions/20638520/appropriate-hashbang-for-node-js-scripts/28646724) explains in detail why this is the correct shebang. – Dan Dascalescu May 03 '19 at 04:21