a snapshot of the terminal showing the output of env dash dash help command

Node.js shebang

$ node yourfile.js
$ ./yourfile.js

Shebang

#!/absolute/path/to/the/interpreter [optional params]
#!/usr/bin/node

Say hello to env

The short answer

#!/usr/bin/env node

Pass parameters to Node.js

#!/usr/bin/env -S node --experimental-module
#!/usr/bin/env -S node -r ./my/other/file.js
#!/usr/bin/env -S node --inspect

Set environment variables

#!/usr/bin/env -S NODE_ENV=production node
#!/usr/bin/env -S NODE_OPTIONS=--experimental-modules node

Start with an empty environment

#!/usr/bin/env -S -i node
#!/usr/bin/env -S - node

Force-disable DEBUG

#!/usr/bin/env -S -u=DEBUG - node

Lock the Node.js runtime version

#!/usr/bin/env -S npx node@6

Run it with TypeScript

#!/usr/bin/env ts-node

References

--

--

I’ve moved to Substack: https://blog.alexewerlof.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store