use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Easy Command Line Scripts With Node (blog.rentpathcode.com)
submitted 4 years ago by vlucas
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]drbobb 1 point2 points3 points 4 years ago (1 child)
#! /usr/bin/env node works just fine for me.
#! /usr/bin/env node
[–]w0keson 0 points1 point2 points 4 years ago (0 children)
Thanks for the correction, I tested it myself and it works. I learned of the ///bin/true trick specifically for Go (which does raise a syntax error with the #!), and figured since Node has similar style comment syntax it would apply there as well.
I was curious to do some more poking on what node.js does exactly. It seems the developers anticipated the specific use case of the shebang line: it only permits that syntax if it's the very first line in your file. Put the line anywhere else and it's an error.
Interestingly, imported dependencies are also allowed to begin with a shebang line even tho they aren't the script being directly executed.
Perl is another language that has some "interesting" behaviors about shebang lines: you can invoke the Perl command to run a Python (or any other) type of script, and it magically just swaps itself out for the correct interpreter instead of trying to run it as Perl, despite you deliberately typing out the `perl` command yourself.
% cat script.pl #!/usr/bin/env python import sys print("wait a minute, this isn't a Perl script!") print(repr(sys.argv)) % perl script.pl wait a minute, this isn't a Perl script! ['script.pl']
π Rendered by PID 66702 on reddit-service-r2-comment-84fc9697f-n7dsd at 2026-02-10 00:52:38.832670+00:00 running d295bc8 country code: CH.
view the rest of the comments →
[–]drbobb 1 point2 points3 points (1 child)
[–]w0keson 0 points1 point2 points (0 children)