Question about templating engines (EJS specifically)

I’m currently working on the URL shortener and I was wondering how do I send data to the ejs file without using res.render again? I guess I should have prefaced this by saying that I made a basic UI for the project. Whenever I press the button to shorten the URL, it posts the data to the server, where it’s processed and a new URL is generated. I want to be able to send this data to the ejs file without rendering again. Is there any way of doing this?

You can’t output a template without rendering. You can write some client side AJAX that will fetch data from your sever and display it, though.

Got it. Thanks for the reply! So every time I want to render some data to template from the server, I would have to call res.render()? Won’t this refresh the entire page each time? I guess that’s what AJAX is for.

I’m not trying to discourage you since eventually you’ll need a front end, but does the URL shortener require it? I think I displayed mine as JSON objects in the browser, no view needed.

It’s cool, it doesn’t really require a front end. I may have gotten a wee bit carried away, but I got it to work. This was more a question for future projects when I have to worry about performance and how many times the browser will reload.

sounds like you are on your way to learning React

@codefu-chivy Hi, If i were you, I would use nunjuck instead of EJS. In case you havn’t tried it yet. I kindly suggest you to do so.