Reputation: 861
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>
Upvotes: 7
Views: 11457
Reputation: 719
<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%>
Upvotes: 18