Npm install node-red-contrib-moment

Hi,
Im trying to install the moment node. But the installation failed.

root@MSK-IOT2050-nodered:~/.node-red# npm install node-red-contrib-moment
npm ERR! code EAI_AGAIN
npm ERR! errno EAI_AGAIN
npm ERR! request to https://registry.npmjs.org/node-red-contrib-moment failed, reason: getaddrinfo EAI_AGAIN registry.npmjs.org registry.npmjs.org:443

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2021-12-10T11_14_32_087Z-debug.log
root@MSK-IOT2050-nodered:~/.node-red#

Does anyone know how I can fix this? I also tried an older version. Same error
best regards

EAI_AGAIN is a DNS lookup timed out error, means it is a network connectivity error or proxy related error.

Does the computer/device running node-red have internet access?

To be clear, the browser looking at the node-red editor may have internet access but the remote device running node-red may not. Its the node-red server that needs internet access.

1 Like

I got it. My ISP seems to have DNS problems. I switched to google DNS and it worked...
Thanks for your help.

The moment node is in my opinion no longer necessary - as the moment library is available via JSONATA

1 Like

How would you do that? All I want is to display DD.MM.YYYY HH:mm:ss in a text node.

No need for moments or a change node here then. Use Angular date format in the ui-text node

[{"id":"68f4441.ac182bc","type":"inject","z":"c791cbc0.84f648","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":220,"y":720,"wires":[["f67b8ec6.0e3ac8"]]},{"id":"f67b8ec6.0e3ac8","type":"ui_text","z":"c791cbc0.84f648","group":"8b5cde76.edd58","order":9,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload | date : \"yyyy-MM-dd HH:mm:ss\"}}","layout":"row-spread","x":400,"y":720,"wires":[]},{"id":"8b5cde76.edd58","type":"ui_group","name":"","tab":"8f03e639.85956","order":1,"disp":true,"width":"12","collapse":false},{"id":"8f03e639.85956","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]
{{msg.payload | date : "dd-MM-yyyy HH:mm:ss"}}

https://docs.angularjs.org/api/ng/filter/date

If you want to use moments in a change node, set it to JSONata and enter.

$moment(payload).tz("Europe/London").format("DD-MM-YYYY HH:mm:ss")

If you leave payload out it will format curent time/date.

1 Like

Much easier only a Change Node

[
    {
        "id": "39d58864.e30568",
        "type": "change",
        "z": "54b226bc.0793e8",
        "name": "Change $moment",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "$moment(payload).format('DD.MM.YYYY HH:mm:ss')",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 690,
        "y": 720,
        "wires": [
            [
                "5b19f997.84aa98"
            ]
        ]
    }
]

just the following String in JSONATA - regardless if change, switch, inject node -

$moment(payload).format('DD.MM.YYYY HH:mm:ss')

or current time (now):

$moment().format('DD.MM.YYYY HH:mm:ss')

You can use all format strings which are offered by the moments library:
https://momentjs.com/docs/#/displaying/

Here a flow with a lot of examples how to use the moment library with out of the box nodes. :wink: However the descriptions in the nodes are in German:

moments.json (40,4 KB)

Important is that you can also provide input format strings for proper interpretation of date strings.

2 Likes

I've seen loads of issues with the Google DNS's, in the end I switched to the AdGuard DNS's which, for me are always significantly faster than any of the other public DNS's. They also provide some protection against unwanted advertising and malware.

There is a bit of a backlog on the moment node I'm afraid, I've just not had the time or energy to do anything with it recently due to work and family pressures. It could also do with switching from MomentJS to DayJS because Moment is no longer under development.

But it does serve some different purposes than JSONata and can be a lot easier to use for some people as it doesn't require any code or knowledge of JSONata at all.

1 Like

Slightly off topic but recommend DNS Benchmark from GRC to see what is the best dns server (I'm not affiliated but use it myself). https://www.grc.com/dns/benchmark.htm

1 Like

Yes, that is definately useful & I've used it in the past. But also, Telegraf has a useful feature that lets you check multiple DNS servers continuously.

This can really help you see where things are going wrong. As you can see on my 15d chart where I had several days with really bad responses. I also continuously ping some common web endpoints as you can see in the last chart. This shows that even pings to my router were disturbed. Possibly this represents some really heavy traffic on the local network. I'm now also using a Telegraf to check speedcheck.net and I think I have it set to check too often which may have caused that disruption. Looking at the current figures I think that I may need to reduce the frequency yet again.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.