6

Does the pound sign (#) start a comment in JavaScript? I have a website I am using with NPM and when I tried to minify the JavaScript with Grunt, Uglify threw the error:

Warning: Uglification failed.
Unexpected character '#'.
Line 1 in app/min-libs/node_modules/grunt-contrib-jshint/node_modules/jshint/nod
e_modules/cli/examples/cat.js
 Use --force to continue.

The file name being referred to seems to be from another NPM module, meaning they know what they are doing. So when I went to app/min-libs/node_modules/grunt-contrib-jshint/node_modules/jshint/node_modules/cli/examples/cat.js, the offending line says:

#!/usr/bin/env node

Is this a comment or do the owners of this NPM module know some super-secret forbidden JavaScript technique?

trysis
  • 7,124
  • 12
  • 47
  • 74

1 Answers1

6

It is not a JavaScript technique, but a *nix OS one. It is called shebang. Quoting from Wiki

Under Unix-like operating systems, when a script with a shebang is run as a program, the program loader parses the rest of the script's initial line as an interpreter directive; the specified interpreter program is run instead, passing to it as an argument the path that was initially used when attempting to run the scrip

So, the cat.js file can be executed in the shell, like an executable (if it has executable permission).

cat.js

instead of

node cat.js
thefourtheye
  • 206,604
  • 43
  • 412
  • 459
  • Wow, you learn something new every day. I guess I'll have to find a way to get Uglify to ignore files that have this shebang thing. Thanks. – trysis Jan 10 '14 at 05:54
  • If I may ask, @thefourtheye, where did your profile name come from? I know the 3rd eye is the eye that can see the imagination or something, so what is the 4th eye? – trysis Jan 10 '14 at 05:56
  • 1
    @trysis You are welcome :) As per hindu mythology [lord Shiva has three eyes](http://en.wikipedia.org/wiki/Shiva#Attributes). Since he has the name the third eye, I took the fourth eye :P – thefourtheye Jan 10 '14 at 05:58
  • @trysis Thank you :) Please consider accepting this answer, if it helps you :) – thefourtheye Jan 10 '14 at 06:00