ReLaXed icon indicating copy to clipboard operation
ReLaXed copied to clipboard

Load JSON and listen to changes?

Open frankandrobot opened this issue 4 years ago • 3 comments

I create a PUG that loads a JSON file. The problem is that relaxedjs does not update when I make changes to this file.

Here's the PUG that loads a JSON file:

-
  const fs = require('fs');
  const data = JSON.parse(fs.readFileSync("./my.json"));
 
section
   p  #{data.foo} 

when I make changes to my.json, the console reports No process defined for file /my.json. and does NOT rebuild the document.

frankandrobot avatar Apr 02 '20 01:04 frankandrobot

Hi @frankandrobot

const data = JSON.parse(fs.readFileSync("./my.json"));

This reads only once in NodeJS.

DanielRuf avatar Apr 02 '20 07:04 DanielRuf

The file watching should work when you use the relaxed binary. When you use it as Node module you have to adjust your code.

https://github.com/RelaxedJS/ReLaXed/tree/master/test/samples/pug/data_require

https://github.com/RelaxedJS/ReLaXed/blob/master/README.md#getting-started

DanielRuf avatar Apr 02 '20 07:04 DanielRuf

Still not working... The problem is that it still reads the file fine on load but then does not scan for changes. If you make a change to file.json, it still says No process defined for file /file.json. What version of relaxed does this apply to?

npx relaxed file.pug -t ./ 
-
  const path = require('path');
  const data = require(path.join(basedir, 'file.json'));

section
   p  #{data.foo} 

UPDATE: upgraded to latest 0.2.4 and still seeing the same behavior, node version = 8.15.1

frankandrobot avatar Apr 03 '20 01:04 frankandrobot