In node-red how to get the file last modified timestamp

#1

In node-red as watch node will be triggered for modification I'm trying to get the last file modified time, but is there any node to get the file last modified time.

0 Likes

#2

If you are using a watch node then the last modified time is now.

0 Likes

#3

No to solve watch node problem only i'm using file last modified time. Is there any node or how to get that.

0 Likes

#4

If you can't find one serching the flows library why not write one?

0 Likes

#5

Yeah i can write in function but I am using node-red snap. So, for using any module I have to edit settings.js to add that library, But in node-red snap I didnt found settings.js.

0 Likes

#6

for reading I wrote the below function but it is giving following exception

fs.stat("/dir/file.txt", function(err, stats){
    var mtime = new Date(util.inspect(stats.mtime));
    console.log(mtime);
});

ReferenceError: fs is not defined (line 1, col 13)

0 Likes

#7

What platform and OS are you running on?
Why not follow the directions here https://nodered.org/docs/getting-started/ ?

I've never seen SNAP till you mentioned it, but settings.js should be in the .node-red folder (ina normal install)

0 Likes

#8

answered in another thread - In node-red snap how to change the settings.js file

0 Likes

#9

What watch node problem? If you mean the fact that you only want one message as in the other thread then you can do that much easier than looking at the last modified time by using a Trigger node as I suggested. It is trivially easy.

0 Likes

#10

But watch node will trigger if content is not saved(i mean even if you try to modify it'll trigger), but I want trigger only when the content is changed(i mean saved).

0 Likes

#11

In what way do you mean 'try to modify' that does not actually modify it?

0 Likes

#12

I used shell scripting in node-red for getting last modified date and time.
script: date -r <filename>

0 Likes

#13

You never explained why the watch node would not do the job.

0 Likes

#14

In linux if the user doesnt have have permission but if he tries to modify then also the last modified date changes so watch node will also be trigerred. But I wanted that the trigger should come once the content in file changes.

So I used variable for storing the content and for comparison, as the content is from gpio it will be either 0 or 1 but the trigger will be from watch node only(if watch node triggers also, i am checking whether the content is changing or not ). I have not used last modified date as solution but I tried to answer as it may help some one and they dont have to include any library.

0 Likes

#15

If you are writing the gpio state to a file then reading it back somewhere else, have you considered using MQTT to send the value? That would be the usual way to do that, unless you have an unusual requirement.

0 Likes

#16

Yeah I am sending to mqtt

0 Likes

#17

Why are you reading it from a file then?

0 Likes