How does the express framework front page call the server method?

  node.js, question

In the process of processing and sending mobile phone verification codes, problems were encountered:

Click the "Send Verification Code" button to execute the method of sending verification code.  However, this method of sending verification code is written on the front page to process the file inside. If some modules of require will naturally report errors, how to handle such problems gracefully?

Express routing provides API, front-end call