为什么Express不使用JavaScript来引导?

时间:2021-01-04 20:39:33

I am currently getting my feet wet using Express. To start out, I used express-generator to scaffold a simple app.

我目前正在使用Express弄湿我的脚。首先,我使用快速生成器来构建一个简单的应用程序。

While examining the project, I noticed that the npm start command is mapped to a binary (bin/www). Upon further inspection I noticed that this file actually contains code to be executed in Node, hence the #!/usr/bin/env node pragma. For anyone having a deeper understanding of Express/Node the answer may be obvious, but still I am wondering: Why didn't they simply use a .js file to bootstrap the framework. That file could then be run using node www.js, I imagine.

在检查项目时,我注意到npm start命令被映射到二进制文件(bin / www)。经过进一步检查,我注意到这个文件实际上包含要在Node中执行的代码,因此是#!/ usr / bin / env节点pragma。对于任何对Express / Node有更深入理解的人来说,答案可能是显而易见的,但我仍然想知道:为什么他们不是简单地使用.js文件来引导框架。然后,我可以使用节点www.js运行该文件。

1 个解决方案

#1


0  

There are probably a few reasons why the script was made an executable

脚本可以成为可执行文件的原因可能有几个

  • npm scripts can be mapped to execute local JS files in the project or executables on the system.
  • 可以映射npm脚本以执行项目中的本地JS文件或系统上的可执行文件。

  • By mapping npm start to bin/www it is effectively the same as running ./bin/www on the command line with the important distinction that by running it via a npm start, it will also work cross platform (e.g. on systems that ignore the hashbang statement, like Windows), otherwise you would need to run it as node bin/www on those systems.
  • 通过将npm start映射到bin / www,它实际上与在命令行上运行./bin/www相同,但重要的区别在于通过npm start运行它,它也可以跨平台工作(例如,在忽略hashbang语句,如Windows),否则你需要在这些系统上将其作为节点bin / www运行。

  • There's a binary ready to add to startup scripts.
  • 有一个二进制文件准备添加到启动脚本。

#1


0  

There are probably a few reasons why the script was made an executable

脚本可以成为可执行文件的原因可能有几个

  • npm scripts can be mapped to execute local JS files in the project or executables on the system.
  • 可以映射npm脚本以执行项目中的本地JS文件或系统上的可执行文件。

  • By mapping npm start to bin/www it is effectively the same as running ./bin/www on the command line with the important distinction that by running it via a npm start, it will also work cross platform (e.g. on systems that ignore the hashbang statement, like Windows), otherwise you would need to run it as node bin/www on those systems.
  • 通过将npm start映射到bin / www,它实际上与在命令行上运行./bin/www相同,但重要的区别在于通过npm start运行它,它也可以跨平台工作(例如,在忽略hashbang语句,如Windows),否则你需要在这些系统上将其作为节点bin / www运行。

  • There's a binary ready to add to startup scripts.
  • 有一个二进制文件准备添加到启动脚本。