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*.
0 commit comments