# Dynamically create/run function node

**URL:** https://discourse.nodered.org/t/dynamically-create-run-function-node/29770
**Category:** General
**Created:** [9 July 2020 08:44 UTC](https://discourse.nodered.org/t/dynamically-create-run-function-node/29770 "2020-07-09T08:44:39Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Henjoe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/henjoe/32/52335_2.png) [@Henjoe](https://discourse.nodered.org/u/Henjoe)
#### Post date: [9 July 2020 08:44 UTC](https://discourse.nodered.org/t/dynamically-create-run-function-node/29770/1 "2020-07-09T08:44:39Z")

</div>

Dear nodered users,

I am actually creating a program where the users will create a text file based code of any javascript code, and this file will be loaded on our nodered.

Is there anyway to run that pre-created javascript code into a function node? I tried the EVAL function, but this code is not efficient and slow.  
I hope there are some ways where I can dynamically create a function in nodered in a more efficient way ( what do I mean by efficient is, it is running like it was created in a function node )

Hopefully you can help me.

Thanks nodered commununity!

Cheers!

---

<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: [9 July 2020 09:36 UTC](https://discourse.nodered.org/t/dynamically-create-run-function-node/29770/2 "2020-07-09T09:36:48Z")

</div>

There are a couple of old nodes [https://flows.nodered.org/search?term=file-function&type=node&type=flow&type=collection](https://flows.nodered.org/search?term=file-function&type=node&type=flow&type=collection) that allow you to use external files to load functions...

But then again - I would be very wary of letting any random user code be able to be executed unless you are going to sanitise it all for bad actions. This is why things like exec are really not a good idea.

---

<div class="post-metadata">

### Author: ![Henjoe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/henjoe/32/52335_2.png) [@Henjoe](https://discourse.nodered.org/u/Henjoe)
#### Post date: [9 July 2020 09:53 UTC](https://discourse.nodered.org/t/dynamically-create-run-function-node/29770/3 "2020-07-09T09:53:04Z")

</div>

Thanks dceejay! Never knew about this! 🙂

---

<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: [7 September 2020 09:53 UTC](https://discourse.nodered.org/t/dynamically-create-run-function-node/29770/4 "2020-09-07T09:53:09Z")

</div>

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