# Using npm module

**URL:** <https://discourse.nodered.org/t/using-npm-module/81977>\
**Category:** General\
**Created:** [12 October 2023 16:49 UTC](https://discourse.nodered.org/t/using-npm-module/81977 "2023-10-12T16:49:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Greg50100](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/greg50100/32/83556_2.png) [@Greg50100](https://discourse.nodered.org/u/Greg50100)\
**Post date:** [12 October 2023 16:49 UTC](https://discourse.nodered.org/t/using-npm-module/81977/1 "2023-10-12T16:49:58Z")

</div>

Hi,

I'm new to Node Red and I would like to use the astronomy-engine npm module ([astronomy-engine - npm](https://www.npmjs.com/package/astronomy-engine)) in node npm but I can't find any examples to help me.

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

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [12 October 2023 17:00 UTC](https://discourse.nodered.org/t/using-npm-module/81977/2 "2023-10-12T17:00:55Z")

</div>

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](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.

1. Restart Node RED

2. In a **function** node declare its use under **setup**  
 ![Screenshot 2023-10-12 at 17.59.46](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/9/19dcb70a813d9fba375c81113b84605619aede77.png)

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

---

<div class="post-metadata">

**Author:** ![Greg50100](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/greg50100/32/83556_2.png) [@Greg50100](https://discourse.nodered.org/u/Greg50100)\
**Post date:** [12 October 2023 20:16 UTC](https://discourse.nodered.org/t/using-npm-module/81977/3 "2023-10-12T20:16:24Z")

</div>

Thank you very much for your help.

here is an example

```auto
[{"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"]]}]

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [26 October 2023 20:16 UTC](https://discourse.nodered.org/t/using-npm-module/81977/4 "2023-10-26T20:16:37Z")

</div>

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