Using npm module

Hi,

I'm new to Node Red and I would like to use the astronomy-engine npm module (astronomy-engine - npm) in node npm but I can't find any examples to help me.

Is it possible to have some help to extract the functions?

Welcome to the forums @Greg50100,

It may be worth searching for a Node that has already wrapped this in a Node RED Node, search here : https://flows.nodered.org

If not, it may still be possible, but its going to require some setup.

  1. Ensure your installation allows to use 3rd party modules in Function nodes.
    You do this by enabling a setting in settings.js line 455.

    functionExternalModules: true,
    Screenshot 2023-10-12 at 17.55.43
    settings.js is usually in your Node Red user directory (example /home/pi/.node-red/settings.js)

  1. Restart Node RED

  2. In a function node declare its use under setup
    Screenshot 2023-10-12 at 17.59.46

  3. Then the various code blocks in the function node will now be able to use its exports
    astronomyEngine.something

Thank you very much for your help.

here is an example

[{"id":"3ace5553b59447a8","type":"function","z":"80fb9cd6399ef672","name":"astronomicalDawn","func":"var latitude = 49.62734;\nvar longitude = -1.61789;\nvar elevation = 3;\nvar now = new Date();\nlet observer = new astronomyEngine.Observer(latitude, longitude, elevation);\n\nmsg.payload = astronomyEngine.SearchAltitude('Sun', observer, +1, now, 300, -18);;\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"astronomyEngine","module":"astronomy-engine"}],"x":450,"y":240,"wires":[["cb3b2157426f97eb"]]},{"id":"cb3b2157426f97eb","type":"debug","z":"80fb9cd6399ef672","name":"debug 17","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":660,"y":240,"wires":[]},{"id":"bd15675083ddb944","type":"inject","z":"80fb9cd6399ef672","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":"3","topic":"","payload":"","payloadType":"date","x":210,"y":240,"wires":[["3ace5553b59447a8"]]}]
1 Like

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