Use require with html
To my knowledge, running node.js within HTML is only possible within desktop app frameworks like NW.js
What you want is to have a backend server in Node.js. Use Express to serve your HTML pages. You can run that code which you need to on the backend server. In the HTML, you can to GET/POST to a certain url in your project when you want to execute the code. On the backend, you can execute the code when that request is made, and send back the output as the response.