[英]Benefits of using bin files over .js in express-generator
If one wants to jump start a project in Node.js with express. 如果要使用express快速启动Node.js中的项目。 one would use
express-generator
. 一个将使用
express-generator
。 After creating a new project your file tree will look like this 创建新项目后,您的文件树将如下所示
.
├── app.js
├── bin
│ └── www
├── package.json
├── public
│ ├── images
│ ├── javascripts
│ └── stylesheets
│ └── style.css
├── routes
│ ├── index.js
│ └── users.js
└── views
├── error.pug
├── index.pug
└── layout.pug
One thing that stood out for me is that to run the app you need to do node bin/www
or a predefined shortcut npm run
. 对我而言突出的一件事是,要运行该应用程序,您需要执行
node bin/www
或预定义的快捷方式npm run
。 My question is why would one use the www
the way it is and not add a .js
extension and remove #!/usr/bin/env node
from the top of the file? 我的问题是,为什么
.js
使用www
而不添加.js
扩展名并从文件顶部删除#!/usr/bin/env node
? Are there any benefits of doing it this way or is it a personal preference? 以这种方式进行操作是否有任何好处?还是个人喜好?
Let's look at the first line of the bin/www
file: 让我们看一下
bin/www
文件的第一行:
#!/usr/bin/env node
This shebang
tells the *nix operating system how to interpret the file if you try to run it as a program. 如果您尝试将其作为程序运行,则该
shebang
告诉* nix操作系统如何解释该文件。
So this file can be started as a program. 因此,该文件可以作为程序启动。 And in Linux traditionally executable files do not have an extension.
而且在Linux中,传统上可执行文件没有扩展名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.