I'm running a simple Node.js server, and I have a function defined that I want to load as in inline script (in an HTML file/template) and then send that template to the client. I guess this is essentially basic Server Side Rendering (SSR)?
I'm not sure how to go about this though... I though it would be really simple but am having some trouble. I've tried templating with EJS but have not have any luck so far. But I'm pretty new to EJS and server side templating some I may be missing something really simple.
This is the type of code/template I'm trying, where initUser
is the function I want inline:
app.get('/*', (req, res) => {
res.render('test-template', {
initUser: initUser,
});
});
<body>
<h1>An EJS template</h1>
<script>
('<%= initUser %>');
</script>
</body>
But then in the browser after I hit the end point and look in the elements tab of dev tools this is what I see:
<script>
('[object Object]')
</script>
Can anyone point me in the right direction? I feel like this should be relativity simple and I'm probably missing something obvious but I would really appreciate some help.