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

**URL:** <https://discourse.nodered.org/t/in-node-red-how-to-get-the-file-last-modified-timestamp/8402>\
**Category:** General\
**Created:** [26 February 2019 13:01 UTC](https://discourse.nodered.org/t/in-node-red-how-to-get-the-file-last-modified-timestamp/8402 "2019-02-26T13:01:55Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![VIKRAMAS](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vikramas/32/3955_2.png) [@VIKRAMAS](https://discourse.nodered.org/u/VIKRAMAS)\
**Post date:** [26 February 2019 13:01 UTC](https://discourse.nodered.org/t/in-node-red-how-to-get-the-file-last-modified-timestamp/8402/1 "2019-02-26T13:01:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [26 February 2019 13:15 UTC](https://discourse.nodered.org/t/in-node-red-how-to-get-the-file-last-modified-timestamp/8402/2 "2019-02-26T13:15:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![VIKRAMAS](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vikramas/32/3955_2.png) [@VIKRAMAS](https://discourse.nodered.org/u/VIKRAMAS)\
**Post date:** [26 February 2019 13:39 UTC](https://discourse.nodered.org/t/in-node-red-how-to-get-the-file-last-modified-timestamp/8402/3 "2019-02-26T13:39:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [26 February 2019 13:40 UTC](https://discourse.nodered.org/t/in-node-red-how-to-get-the-file-last-modified-timestamp/8402/4 "2019-02-26T13:40:33Z")

</div>

If you can't find one serching the [flows library](https://flows.nodered.org/) why not write one?

---

<div class="post-metadata">

**Author:** ![VIKRAMAS](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vikramas/32/3955_2.png) [@VIKRAMAS](https://discourse.nodered.org/u/VIKRAMAS)\
**Post date:** [26 February 2019 13:51 UTC](https://discourse.nodered.org/t/in-node-red-how-to-get-the-file-last-modified-timestamp/8402/5 "2019-02-26T13:51:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![VIKRAMAS](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vikramas/32/3955_2.png) [@VIKRAMAS](https://discourse.nodered.org/u/VIKRAMAS)\
**Post date:** [26 February 2019 13:53 UTC](https://discourse.nodered.org/t/in-node-red-how-to-get-the-file-last-modified-timestamp/8402/6 "2019-02-26T13:53:05Z")

</div>

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

```auto
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)

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [26 February 2019 15:12 UTC](https://discourse.nodered.org/t/in-node-red-how-to-get-the-file-last-modified-timestamp/8402/7 "2019-02-26T15:12:52Z")

</div>

> [@VIKRAMAS](#):
>
> but I am using node-red snap

What platform and OS are you running on?  
Why not follow the directions here [Getting Started : Node-RED](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)

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [26 February 2019 15:37 UTC](https://discourse.nodered.org/t/in-node-red-how-to-get-the-file-last-modified-timestamp/8402/8 "2019-02-26T15:37:33Z")

</div>

answered in another thread - [In node-red snap how to change the settings.js file](https://discourse.nodered.org/t/in-node-red-snap-how-to-change-the-settings-js-file/8411/2)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [26 February 2019 16:04 UTC](https://discourse.nodered.org/t/in-node-red-how-to-get-the-file-last-modified-timestamp/8402/9 "2019-02-26T16:04:46Z")

</div>

> [@VIKRAMAS](#):
>
> No to solve watch node problem

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.

---

<div class="post-metadata">

**Author:** ![VIKRAMAS](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vikramas/32/3955_2.png) [@VIKRAMAS](https://discourse.nodered.org/u/VIKRAMAS)\
**Post date:** [27 February 2019 11:01 UTC](https://discourse.nodered.org/t/in-node-red-how-to-get-the-file-last-modified-timestamp/8402/10 "2019-02-27T11:01:05Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [27 February 2019 11:38 UTC](https://discourse.nodered.org/t/in-node-red-how-to-get-the-file-last-modified-timestamp/8402/11 "2019-02-27T11:38:32Z")

</div>

> [@VIKRAMAS](#):
>
> watch node will trigger if content is not saved(i mean even if you try to modify it'll trigger)

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

---

<div class="post-metadata">

**Author:** ![VIKRAMAS](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vikramas/32/3955_2.png) [@VIKRAMAS](https://discourse.nodered.org/u/VIKRAMAS)\
**Post date:** [3 March 2019 10:12 UTC](https://discourse.nodered.org/t/in-node-red-how-to-get-the-file-last-modified-timestamp/8402/12 "2019-03-03T10:12:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [3 March 2019 10:47 UTC](https://discourse.nodered.org/t/in-node-red-how-to-get-the-file-last-modified-timestamp/8402/13 "2019-03-03T10:47:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![VIKRAMAS](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vikramas/32/3955_2.png) [@VIKRAMAS](https://discourse.nodered.org/u/VIKRAMAS)\
**Post date:** [3 March 2019 10:57 UTC](https://discourse.nodered.org/t/in-node-red-how-to-get-the-file-last-modified-timestamp/8402/14 "2019-03-03T10:57:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [3 March 2019 11:23 UTC](https://discourse.nodered.org/t/in-node-red-how-to-get-the-file-last-modified-timestamp/8402/15 "2019-03-03T11:23:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![VIKRAMAS](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vikramas/32/3955_2.png) [@VIKRAMAS](https://discourse.nodered.org/u/VIKRAMAS)\
**Post date:** [3 March 2019 11:36 UTC](https://discourse.nodered.org/t/in-node-red-how-to-get-the-file-last-modified-timestamp/8402/16 "2019-03-03T11:36:52Z")

</div>

Yeah I am sending to mqtt

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [3 March 2019 11:39 UTC](https://discourse.nodered.org/t/in-node-red-how-to-get-the-file-last-modified-timestamp/8402/17 "2019-03-03T11:39:14Z")

</div>

Why are you reading it from a file then?
