Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using Node.js and Express, how to hide Javascript code in backend?

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading