Skip to content Skip to sidebar Skip to footer

Make Node.js Support The Shebang (#!) For Javascript Files

Some scripting languages (such as Python or Bash) use # for comments. #!/usr/bin/env python print 'hello, world' I can run the script: python script.py Or ./script.py Is it poss

Solution 1:

Yes, you can simply use #!/usr/bin/env node (or whatever the name of your JavaScript interpreter is, it works fine with js (spidermonkey), too).

[me@hades:~]> cat > test.js
#!/usr/bin/env node
console.log('hi');
[me@hades:~]> chmod +x test.js
[me@hades:~]> ./test.js
hi

Most likely both interpreters test if the first line begins with #! and in this case it is skipped.

Post a Comment for "Make Node.js Support The Shebang (#!) For Javascript Files"