简体   繁体   中英

Benefits of using bin files over .js in express-generator

If one wants to jump start a project in Node.js with express. one would use 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 . 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? 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:

#!/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.

So this file can be started as a program. And in Linux traditionally executable files do not have an extension.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM