0

There are two files: 1)app.js and 2) browser.html. app.js just stores a value in a node-js local storage and browser.html should alerts that. But browser.html alerts "null". My JavaScript code:

var LocalStorage = require('node-localstorage').LocalStorage;
    localStorage = new LocalStorage('./scratch');
var a="salam";
    global.a=a;
    localStorage.setItem('a',a);

My html code:

<!DOCTYPE html>
<html lang="en">
  <head>
<title>TEST</title>
   </head>
<body>
<input value="Smart contract data" max="25" id="12"></input>
    <script src='js/app.js'>  </script>
    <script>
    alert(localStorage.getItem('a'));
  </script>
  </body>
</html>

What is the problem and its solution? Is there any way to communicate between node-js storage and a html file? Please guide a beginner man.

Alireza
  • 227
  • 1
  • 11

1 Answers1

0

The issue here is that node-localstorage is entirely backend, and htlm5 localStorage is entirely client side. You will not be able to pull backend values set with node-localstorage on the client end.

In order to pass values from node to the client you will need a template engine. Express provides a pretty complete list of those engines here: https://expressjs.com/en/resources/template-engines.html

gungthar
  • 184
  • 1
  • 7