Make Node.js support the shebang (#!) for JavaScript files

折月煮酒 提交于 2019-11-29 03:03:53

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!