Node.js passing parameters to client via express render

The variable name you sent to the render function is only available while rendering the page, after it is sent to the client, it is not accessible. You have to use it in your view on the rendering stage.

Since you are using handlebars, you can display it in your page like this, for instance:

<h1>{{ name }}</h1>

If you want to use this data in a javascript, use it inside a script tag:

<script>
  var name = "{{ name }}";
  console.log(name);
</script>

Leave a Comment