Skip to content

Commit 24926ae

Browse files
authored
Update part9b.md
Suggest adding `require.main === module` checks so that scripts work from both the command line and endpoints without interference.
1 parent 6dd571d commit 24926ae

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/content/9/en/part9b.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,8 @@ If the query parameters of the request are of the wrong type or missing, a respo
827827
828828
Do not copy the calculator code to file <i>index.ts</i>; instead, make it a [TypeScript module](https://www.typescriptlang.org/docs/handbook/modules.html) that can be imported into <i>index.ts</i>.
829829
830+
For *calculateBmi* to work correctly from both the command line and the endpoint, consider adding a check *require.main === module* to the file <i>bmiCalculator.ts</i>. It tests whether the module is main, i.e. it is run directly from the command line (in our case, *npm run calculateBmi*), or it is used by other modules that import functions from it (e.g. <i>index.ts</i>). Parsing command-line arguments makes sense only if the module is main. Without this condition, you might see argument validation errors when starting the application via *npm start* or *npm run dev*.
831+
830832
</div>
831833
832834
<div class="content">

0 commit comments

Comments
 (0)