简体   繁体   English

在Express-Generator中使用Bin文件而非.js的好处

[英]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.

相关问题 在 Express 4 和 express-generator 的 /bin/www 中使用 socket.io - Using socket.io in Express 4 and express-generator's /bin/www 当我使用express-generator时,为什么将.bin / www视为没有.js扩展名的javascript文件 - Why .bin/www is consider as a javascript file without the .js extention when I use express-generator 快递发电机不工作 - Express-generator is not working 客户端<script src="“/socket.io/socket.io.js”"></script>未找到,使用 Express-generator 生成的项目 - Client side <script src=“/socket.io/socket.io.js”></script> not found, using Express-generator generated project Windows 10中为node.js安装express和express-generator时出错 - error in Install express and express-generator for node.js in windows 10 express-generator 示例返回 Not Found 错误 - express-generator sample returning Not Found error Node.js express-generator - 由于类型错误,应用程序无法运行:app.set 不是函数 - Node.js express-generator - app can't run due to TypeError: app.set is not a function 无法从另一台计算机使用快速生成器访问NodeJS服务器 - Can't access NodeJS server using express-generator from another computer 快递或快递发电机:我需要两者吗? - express or express-generator: do i need both? Express-generator,Socket.io事件多次发出 - Express-generator, Socket.io Event issuing multiple times
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM