I need to use a process variable inside my ejs template in order to call an endpoint, but from this context I cannot reach the process nodejs variable.
How can I achieve this?
<a class="imgLink" href="#" onclick="get_user_info()">
<div style="border: 2px solid gray;padding: 8px">Info</div>
</a>
<script>
function get_user_info() {
$.get(`/users/${process.env.userId}`, function(data) {
// Do something
})
}
</script>
<a class="imgLink" href="#" onclick="get_user_info()">
<div style="border: 2px solid gray;padding: 8px">Info</div>
</a>
<script>
function get_user_info() {
var userId= '<%= process.env.userId %>';
$.get(`/users/${userId}`, function(data) {
// Do something
})
}
</script>
get the userId using <%= process.env.userId%>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With