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

How can I connect front-end js with back-end js

I’m currently working on a website and I need to let the user send an email from that website. (The email should be sent through a designated email).
So I’m going to use nodemailer, but since the JS is connected to the HTML-Elements, I can’t import any libraries. So I created another JS file that runs back-end, but how do I connect the two? For the “JS Events” it would have to be connected to an HTML-Element.. And well, just calling a function doesn’t work.
Things like requireJS don’t seem like a good choice either since I’d like to handle it back-end.

>Solution :

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

The two options for communicating between client-side JavaScript and server-side code are:

  • HTTP requests
  • WebSockets

Approaches for using them include Forms, (if you are using Node.js for your backend then you are probably using Express, in which case this is a more specific tutorial), Ajax, the WebSocket API, and Socket.io.

For your purposes, forms are the simplest option. Ajax is slightly more complicated but you might prefer the extra flexibility in UX.

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