E
E
exxagw2017-03-02 19:35:52
JavaScript
exxagw, 2017-03-02 19:35:52

How to update data from file in nodejs?

There is a file points.json
var data = require('/points.json');
the file stores data that can be updated. how can update var data inside nodejs? at least once every 24 hours.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yustas Alexu, 2017-03-02
@Yuxus

The easiest way is to force the application to restart every 24 hours. But I would just read this json through the fs module , not through require.
If this option is not suitable, then you can also reset the require cache. But I see no reason not to use fs.
Also, it's better to know directly when a file has changed, rather than guessing. Therefore, fs.watch can be used to watch a file and respond exactly when it changes.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question