I’m new with Node and Express. I would like to ask a question about how to hide Javascript code in backend. I’m using Node.js with Express. I want to avoid reading with browser inspection. I created a simple script and put the link in index.html, inside head, writing <script src ="/javascripts/test.js"></script>. Everything ok, works normally.
I tried to inspect the page, with Google, and the code is easily read by opening .
I think the reason is because i use test.js in the browser front-end side. How can I use it in the backend and avoid that someone can read the code? How can this be done and how? Can you explain me? Thank you
For information and completeness, the script is
function myFunction() {
alert("I am an alert box!");
}
While on the html button I wrote:
<button onclick="myFunction()" type="button" class="btn btn-primary">Primary</button>
>Solution :
The alert function, defined in the HTML specification, causes the browser to display a modal message box using the browser’s native UI. It’s an API made available to client-side JavaScript.
While Node.js allows you to execute JavaScript on the server, it only allows you to use JavaScript language features and Node.JS API (along with third-party code subject to the same limitations).
You can’t use Web APIs or other browser-specific features in Node.js (excepting those which have explicit Node.js equivalents), because the server doesn’t have access to them.
Making a modal message box appear in the browser is inherently something that has to be done in the browser, so there can’t be an equivalent Node.JS API.