# Help Using Other Library Js

**URL:** <https://discourse.nodered.org/t/help-using-other-library-js/41736>\
**Category:** Developing Nodes\
**Created:** [28 February 2021 02:12 UTC](https://discourse.nodered.org/t/help-using-other-library-js/41736 "2021-02-28T02:12:35Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrizkywiguna](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mrizkywiguna/32/32016_2.png) [@mrizkywiguna](https://discourse.nodered.org/u/mrizkywiguna)\
**Post date:** [28 February 2021 02:12 UTC](https://discourse.nodered.org/t/help-using-other-library-js/41736/1 "2021-02-28T02:12:35Z")

</div>

Hi All,

I've read some threads about adding library js, but didn't get work. I want to use library from this site:  
[http://praytimes.org/manual](http://praytimes.org/manual)  
and library is  
[praytimes](http://praytimes.org/code/v2/js/PrayTimes.js)

I've add to my function global

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/b/1b46a45210f06100e2af637cadb34dc88a29f76e.jpeg)

And try to using it as a function. But still not working.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/3/636519bf5be73984c4b1864c635490de081d7aa1.png)

```auto
[{"id":"de86cd8d.e98f7","type":"function","z":"8f3ffe88.a77cf","name":"","func":" var prayTimes = global.get('prayTimes')\n var times = prayTimes.getTimes(new Date(), [43, -80], -5);\nmsg.payload = times;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":630,"y":740,"wires":[["9f6c8586.20b888"]]},{"id":"ad6e6ab9.e346f8","type":"inject","z":"8f3ffe88.a77cf","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":390,"y":740,"wires":[["de86cd8d.e98f7"]]},{"id":"9f6c8586.20b888","type":"debug","z":"8f3ffe88.a77cf","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":840,"y":760,"wires":[]}]

```

Many thanks for your advise, Sir!

---

<div class="post-metadata">

**Author:** ![aderici](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/aderici/32/37279_2.png) [@aderici](https://discourse.nodered.org/u/aderici)\
**Post date:** [28 February 2021 02:41 UTC](https://discourse.nodered.org/t/help-using-other-library-js/41736/2 "2021-02-28T02:41:17Z")

</div>

var PT = new PrayTimes('ISNA');  
var times = PT.getTimes(new Date(), [43, -80], -5);

So you better create a new instance first?

---

<div class="post-metadata">

**Author:** ![mrizkywiguna](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mrizkywiguna/32/32016_2.png) [@mrizkywiguna](https://discourse.nodered.org/u/mrizkywiguna)\
**Post date:** [28 February 2021 11:40 UTC](https://discourse.nodered.org/t/help-using-other-library-js/41736/3 "2021-02-28T11:40:53Z")

</div>

Hi @aderici ,

Thank you for advise. I've try like you said:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/a/4afac021ef1ea80b682f66f0215a67d31074cf86.png)  
But, still not get the output message

---

<div class="post-metadata">

**Author:** ![aderici](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/aderici/32/37279_2.png) [@aderici](https://discourse.nodered.org/u/aderici)\
**Post date:** [28 February 2021 11:42 UTC](https://discourse.nodered.org/t/help-using-other-library-js/41736/4 "2021-02-28T11:42:00Z")

</div>

First get the PrayTimes from global context at the top of the page please

---

<div class="post-metadata">

**Author:** ![mrizkywiguna](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mrizkywiguna/32/32016_2.png) [@mrizkywiguna](https://discourse.nodered.org/u/mrizkywiguna)\
**Post date:** [28 February 2021 11:56 UTC](https://discourse.nodered.org/t/help-using-other-library-js/41736/5 "2021-02-28T11:56:00Z")

</div>

> [@aderici](#):
>
> var PT = new PrayTimes('ISNA');  
> var times = PT.getTimes(new Date(), [43, -80], -5);

Hi, Sir  
After add global.get context:  
var PrayTimes = global.get('prayTimes');  
var PT = new PrayTimes('ISNA');  
var times = PT.getTimes(new Date(), [43, -80], -5);  
msg.payload = times.sunrise;  
return msg;

Here is the output  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/e/4e0901ceda9536bceb34b87e4593b437e5c26de8.png)

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [28 February 2021 12:01 UTC](https://discourse.nodered.org/t/help-using-other-library-js/41736/6 "2021-02-28T12:01:04Z")

</div>

Hi @mrizkywiguna

The file you are trying to use is not packaged as a node.js module - so you cannot `require` it in your settings file.

If you edit `PrayTimes.js` and add the following line to the end of it:

```auto
module.exports = PrayTimes;

```

Then restart Node-RED, your Function should work.

---

<div class="post-metadata">

**Author:** ![mrizkywiguna](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mrizkywiguna/32/32016_2.png) [@mrizkywiguna](https://discourse.nodered.org/u/mrizkywiguna)\
**Post date:** [28 February 2021 12:08 UTC](https://discourse.nodered.org/t/help-using-other-library-js/41736/7 "2021-02-28T12:08:40Z")

</div>

You're The Best Nick!  
Thank you very much, Sir!  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/7/9718386e1a36876e02c831f87f7a59f8ab2e40f2.png)

---

<div class="post-metadata">

**Author:** ![mrizkywiguna](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mrizkywiguna/32/32016_2.png) [@mrizkywiguna](https://discourse.nodered.org/u/mrizkywiguna)\
**Post date:** [28 February 2021 12:49 UTC](https://discourse.nodered.org/t/help-using-other-library-js/41736/8 "2021-02-28T12:49:05Z")

</div>

Hi Sir,

Another questions, how to put this code into function?

> prayTimes.tune( {sunrise: -1, sunset: 3.5} );

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [28 February 2021 13:34 UTC](https://discourse.nodered.org/t/help-using-other-library-js/41736/9 "2021-02-28T13:34:19Z")

</div>

You'll have to explain a bit more about what you mean. I don't know anything about the library you are using, I have never seen it before today.

So when you ask how to put that code into a function, all I can say is just copy and paste it in... but I assume that isn't the sort of answer you are looking for.

---

<div class="post-metadata">

**Author:** ![mrizkywiguna](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mrizkywiguna/32/32016_2.png) [@mrizkywiguna](https://discourse.nodered.org/u/mrizkywiguna)\
**Post date:** [28 February 2021 13:48 UTC](https://discourse.nodered.org/t/help-using-other-library-js/41736/10 "2021-02-28T13:48:04Z")

</div>

I'm sorry, Sir.

Actually the code is working now. But the "time" results need some tune, because it's different from the actual. Based on the manual, this function is for tune the minutes:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/c/fca0dc361e8c37cb4fec1bf9aa6b7c5375eea6c1.png)

---

<div class="post-metadata">

**Author:** ![mrizkywiguna](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mrizkywiguna/32/32016_2.png) [@mrizkywiguna](https://discourse.nodered.org/u/mrizkywiguna)\
**Post date:** [28 February 2021 14:05 UTC](https://discourse.nodered.org/t/help-using-other-library-js/41736/11 "2021-02-28T14:05:45Z")

</div>

Hi Nick,  
Now i'm using this code for some adjusting. Maybe not the best way, but now I can tune it.

```auto
[{"id":"afd685b1.ab3298","type":"ui_text","z":"8f3ffe88.a77cf","group":"7394d5c4.292edc","order":0,"width":"5","height":"3","name":"Isya","label":"Isya","format":"{{msg.payload}}","layout":"col-center","x":990,"y":360,"wires":[]},{"id":"8f5fcb1b.e30bd8","type":"function","z":"8f3ffe88.a77cf","name":"isha","func":"var hms = msg.payload.isha;\n\nvar a = hms.split(':'); // split it at the colons\nvar tune = 4; //tuning\n// minutes are worth 60 seconds. Hours are worth 60 minutes.\nvar seconds = (+a[0]) * 60 * 60 + (+a[1]+tune) * 60; \nmsg.payload = seconds;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":450,"y":360,"wires":[["ce39452a.02d7b8"]]},{"id":"ce39452a.02d7b8","type":"change","z":"8f3ffe88.a77cf","name":"To millisecs","rules":[{"t":"set","p":"payload","pt":"msg","to":"msg.payload*1000","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":360,"wires":[["e6b1f8b5.ac6328"]]},{"id":"e6b1f8b5.ac6328","type":"moment","z":"8f3ffe88.a77cf","name":"","topic":"","input":"payload","inputType":"msg","inTz":"ETC/GMT","adjAmount":"0","adjType":"hours","adjDir":"add","format":"HH:mm","locale":"ID","output":"payload","outputType":"msg","outTz":"ETC/GMT","x":780,"y":360,"wires":[["afd685b1.ab3298"]]},{"id":"7394d5c4.292edc","type":"ui_group","name":"Isya","tab":"10aa04cd.61297b","order":6,"disp":false,"width":"5","collapse":false},{"id":"10aa04cd.61297b","type":"ui_tab","name":"smartprayer","icon":"dashboard","disabled":false,"hidden":false}]

```

---

<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:** [14 March 2021 14:06 UTC](https://discourse.nodered.org/t/help-using-other-library-js/41736/12 "2021-03-14T14:06:17Z")

</div>

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