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?

2
  • 1
    my guess would be you're simply in a wrong directory. ls -l ./my-app should help. Jun 16, 2014 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, 2014 at 22:47

1 Answer 1

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

4
  • @asking you should be able to have the .js part on there Jun 16, 2014 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, 2014 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. Feb 1, 2018 at 16:23
  • This answer explains in detail why this is the correct shebang. May 3, 2019 at 4:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.