# How to create config node in node-red

**URL:** https://discourse.nodered.org/t/how-to-create-config-node-in-node-red/77101
**Category:** Developing Nodes
**Created:** [31 March 2023 06:55 UTC](https://discourse.nodered.org/t/how-to-create-config-node-in-node-red/77101 "2023-03-31T06:55:02Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![natamongkol](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/natamongkol/32/78146_2.png) [@natamongkol](https://discourse.nodered.org/u/natamongkol)
#### Post date: [31 March 2023 06:55 UTC](https://discourse.nodered.org/t/how-to-create-config-node-in-node-red/77101/1 "2023-03-31T06:55:02Z")

</div>

I try create config node like [this](https://nodered.org/docs/creating-nodes/config-nodes) but it's show only text box no config, I want projectid to be a config node, I tried following many nodes with config node but it didn't work for me, How to fix it?

**graphql\_query.js**

```plaintext
module.exports = function(RED) {
    function netpie_graphql_query(nodeConfig) {
        RED.nodes.createNode(this,nodeConfig);
        var node = this;
        node.on('input', function(msg) {
            var gqlquery = nodeConfig.gqlquery;

            nodeConfig.projectid = RED.nodes.getNode(nodeConfig.projectid).projectid;

            const axios = require('axios');
            let data = JSON.stringify({
            query: gqlquery,
            variables: {}
            });

            let axiosConfig = {
            method: 'post',
            maxBodyLength: Infinity,
            url: 'http://gqlv2.aaaaa.io/',
            headers: { 
                'Authorization': 'bearer '+auth.token, 
                'Content-Type': 'application/json'
            },
            data : data
            };

            axios.request(axiosConfig)
            .then((response) => {
            data = (JSON.stringify(response.data));
            msg.payload = data;
            node.send(msg);
            })
            .catch((error) => {
            //console.log(error);
            this.error("Request failed with status code 400, please check your schema");
            });
        });
    }
    RED.nodes.registerType("netpie_graphql_query",netpie_graphql_query);
}

```

**graphql\_query.html**

```auto
    RED.nodes.registerType('netpie_graphql_query',{
        category: 'graphql',
        color:'#00adff',
        defaults:{

            projectid:{value:"", type:"projectid"},

            name:{value:""},
            gqlquery:{value:""}

        },
        inputs:1,
        outputs:1,
        icon:"template.svg",
        label:function(){
            return this.name||"netpie graphql";
        },
        oneditprepare: function() {
            this.editor = RED.editor.createEditor({
            id: 'gqlquery-message-editor',
            mode: 'ace/mode/text',
            value: $("#node-input-gqlquery").val()
        });
        },
        oneditsave: function() {
            $("#node-input-gqlquery").val(this.editor.getValue());
            this.editor.destroy();
            delete this.editor;
        },
        oneditcancel: function() {
            this.editor.destroy();
            delete this.editor;
        }
            
    });
    </script>

    <script type="text/html" data-template-name="netpie_graphql_query">
        <div class="form-row">
            <label for="node-input-name"><i class="fa fa-tag"></i>Name</label>
            <input type = "text" id="node-input-name" placeholder="Name">
        </div>

        <div class="form-row">
            <label for="node-input-projectid"><i class="fa fa-tag"></i>Project ID</label>
            <input type = "text" id="node-input-projectid">
        </div>

        <div class="form-row">
            <label for="node-input-gqlquery"><i class="fa fa-cog"></i> <span>Query</span></label>
            <div style="height: 250px;" class="node-text-editor" id="gqlquery-message-editor"></div>
            <input type="hidden" id="node-input-gqlquery">
        </div>

    </script>

    <script type="text/html" data-help-name="netpie_graphql_query">
        <p>netpie graphql query</p>
    </script>

```

**graphql\_query\_config.js**

```auto
    function projectid(nodeConfig) {
        RED.nodes.createNode(this,nodeConfig);
        this.name = nodeConfig.name;
        this.projectid = nodeConfig.projectid;
    }
    RED.nodes.registerType("projectid",projectid);
}

```

graphql\_query\_config.html

```auto
    RED.nodes.registerType('projectid',{
        category: 'config',
        defaults: {
            name: {value:""},
            projectid: {value:""}
        },
        label: function() {
            return this.name || this.("projectid");
        }
    });
</script>

<script type="text/html" data-template-name="projectid">
    <div class="form-row">
        <label for="node-config-input-name"><i class="fa fa-bookmark"></i> Name</label>
        <input type="text" id="node-config-input-name">
    </div>
    <div class="form-row">
        <label for="node-config-input-projectid"><i class="fa fa-bookmark"></i> projectid</label>
        <input type="text" id="node-config-input-projectid">
    </div>
</script>

```

but projectid is not config node

 ![สกรีนช็อต 2023-03-31 123549](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/2/128dcf2e3ba12bc8dfb7eda4123a69b0054facf9.png)

---

<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: [31 March 2023 08:05 UTC](https://discourse.nodered.org/t/how-to-create-config-node-in-node-red/77101/2 "2023-03-31T08:05:02Z")

</div>

Hi @natamongkol - Welcome to the forums.

I can't help notice this.

```auto
 return this.name || this.("projectid");

```

Should it be

```auto
 return this.name || this.projectid

```

Its to early in the morning for me to know if `this.("projectid")` is valid syntax.

Also, I don't _think_ its invalid to do, but be careful naming config entries to a name that represents its own type name

`RED.nodes.registerType('projectid',{})`  
`projectid: {value:""}`

I cant see anything else that would be a problem - but again its early 😅

---

<div class="post-metadata">

### Author: ![natamongkol](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/natamongkol/32/78146_2.png) [@natamongkol](https://discourse.nodered.org/u/natamongkol)
#### Post date: [31 March 2023 08:10 UTC](https://discourse.nodered.org/t/how-to-create-config-node-in-node-red/77101/3 "2023-03-31T08:10:04Z")

</div>

now i fix it but not working

```auto
return this.name || this.projectid;

```

---

<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: [31 March 2023 08:17 UTC](https://discourse.nodered.org/t/how-to-create-config-node-in-node-red/77101/4 "2023-03-31T08:17:09Z")

</div>

I would rename the config entry in your config node also.

From

```auto
 defaults: {
   name: {value:""},
   projectid: {value:""}
},

```

To

```auto
 defaults: {
   name: {value:""},
   id: {value:""}
},

```

If you think about the module its self.

```auto
module.exports = function (RED) {

  function projectid(nodeConfig) {
          RED.nodes.createNode(this,nodeConfig);
          this.name = nodeConfig.name;
  
           /* This could be causing a problem, as it maybe re-evaluating its self */
          this.projectid = nodeConfig.projectid;
      }
      RED.nodes.registerType("projectid",projectid);
}

```

again, I'm not sure, it just sticks out at me, if trying it, ensure to rename references to it also

---

<div class="post-metadata">

### Author: ![natamongkol](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/natamongkol/32/78146_2.png) [@natamongkol](https://discourse.nodered.org/u/natamongkol)
#### Post date: [31 March 2023 08:29 UTC](https://discourse.nodered.org/t/how-to-create-config-node-in-node-red/77101/5 "2023-03-31T08:29:41Z")

</div>

i try it but not work I've been stuck with this problem for 2 days now. I don't know how to fix this problem. I tried another node example using config node and tried to follow but it didn't work.

---

<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: [31 March 2023 08:40 UTC](https://discourse.nodered.org/t/how-to-create-config-node-in-node-red/77101/6 "2023-03-31T08:40:29Z")

</div>

Anything in the start up logs that might lend a clue, can you paste them here?  
assuming you are using a ~recent Node RED version?

unless my eyes are giving up on me - other than the points I made, I cant see anything else.

---

<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: [31 March 2023 08:43 UTC](https://discourse.nodered.org/t/how-to-create-config-node-in-node-red/77101/7 "2023-03-31T08:43:49Z")

</div>

> [@marcus-j-davies](#):
>
> I would rename the config entry in your config node also.

Noooo! `id` is a reserved property name.

---

<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: [31 March 2023 08:49 UTC](https://discourse.nodered.org/t/how-to-create-config-node-in-node-red/77101/8 "2023-03-31T08:49:42Z")

</div>

Uuhhh

`id` was probably not the best choice in my example 😅

Completely forgot about that gem!

---

<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: [31 March 2023 08:55 UTC](https://discourse.nodered.org/t/how-to-create-config-node-in-node-red/77101/9 "2023-03-31T08:55:20Z")

</div>

I have just copied all of the provided files to my local node-red instance and:

1. fixed the `return this.name || this.("projectid");` line to be `this.projectid`
2. added the missing `<script>` tag at the start of both HTML files
3. added the missing `module.exports = function(RED) {` line at the start of `graphql_query_config.js`

(The last two I assume were copy/paste errors when sharing the code rather than actually missing in your files)

With that done, it works as expected:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/d/ed50229837c9bd67b3b0e39cb403fb570d65f345.png)

What version of Node-RED are you using? Are you fully restarting Node-RED (the runtime, not just reloading the editor) after making changes to the files?

One other recommendation is given you are defining one type as `netpie_graphql_query` I would _not_ use `projectid` as the type for your config node - it is too generic. I suggest changing it to `netpie_graphql_projectid` or something a bit more specific.

---

<div class="post-metadata">

### Author: ![natamongkol](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/natamongkol/32/78146_2.png) [@natamongkol](https://discourse.nodered.org/u/natamongkol)
#### Post date: [31 March 2023 09:09 UTC](https://discourse.nodered.org/t/how-to-create-config-node-in-node-red/77101/10 "2023-03-31T09:09:45Z")

</div>

Node-RED version: v3.0.2, I restart node-red every time I modify the node file, Can you please check if all this is correct?

```auto
const auth = require('../../../../dashboard/module/auth');
module.exports = function(RED) {
    function netpie_graphql_query(nodeConfig) {
        RED.nodes.createNode(this,nodeConfig);
        var node = this;
        node.on('input', function(msg) {
            var gqlquery = nodeConfig.gqlquery;

            nodeConfig.projectid = RED.nodes.getNode(nodeConfig.projectid).projectid;

            const axios = require('axios');
            let data = JSON.stringify({
            query: gqlquery,
            variables: {}
            });

            let axiosConfig = {
            method: 'post',
            maxBodyLength: Infinity,
            url: 'http://gqlv2.netpie.io/',
            headers: { 
                'Authorization': 'bearer '+auth.token, 
                'Content-Type': 'application/json'
            },
            data : data
            };

            axios.request(axiosConfig)
            .then((response) => {
            data = (JSON.stringify(response.data));
            msg.payload = data;
            node.send(msg);
            console.log(this.projectid);
            })
            .catch((error) => {
            //console.log(error);
            this.error("Request failed with status code 400, please check your schema");
            });
        });
    }
    RED.nodes.registerType("netpie_graphql_query",netpie_graphql_query);
}

```

```auto
<script type = "text/javascript">
    RED.nodes.registerType('netpie_graphql_query',{
        category: 'graphql',
        color:'#00adff',
        defaults:{

            projectid:{value:"", type:"projectid"},

            name:{value:""},
            gqlquery:{value:""}

        },
        inputs:1,
        outputs:1,
        icon:"template.svg",
        label:function(){
            return this.name||"netpie graphql";
        },
        oneditprepare: function() {
            this.editor = RED.editor.createEditor({
            id: 'gqlquery-message-editor',
            mode: 'ace/mode/text',
            value: $("#node-input-gqlquery").val()
        });
        },
        oneditsave: function() {
            $("#node-input-gqlquery").val(this.editor.getValue());
            this.editor.destroy();
            delete this.editor;
        },
        oneditcancel: function() {
            this.editor.destroy();
            delete this.editor;
        }
            
    });
    </script>

    <script type="text/html" data-template-name="netpie_graphql_query">
        <div class="form-row">
            <label for="node-input-name"><i class="fa fa-tag"></i>Name</label>
            <input type = "text" id="node-input-name" placeholder="Name">
        </div>

        <div class="form-row">
            <label for="node-input-projectid"><i class="fa fa-tag"></i>Project ID</label>
            <input type = "text" id="node-input-projectid">
        </div>

        <div class="form-row">
            <label for="node-input-gqlquery"><i class="fa fa-cog"></i> <span>Query</span></label>
            <div style="height: 250px;" class="node-text-editor" id="gqlquery-message-editor"></div>
            <input type="hidden" id="node-input-gqlquery">
        </div>

    </script>

    <script type="text/html" data-help-name="netpie_graphql_query">
        <p>netpie graphql query</p>
    </script>

```

```auto
module.exports = function(RED) {
    function projectid(nodeConfig) {
        RED.nodes.createNode(this,nodeConfig);
        this.name = nodeConfig.name;
        this.projectid = nodeConfig.projectid;
    }
    RED.nodes.registerType("projectid",projectid);
}

```

```auto
<script type="text/javascript">
    RED.nodes.registerType('projectid',{
        category: 'config',
        defaults: {
            name: {value:""},
            projectid: {value:""}
        },
        label: function() {
            return this.projectid
        }
    });
</script>

<script type="text/html" data-template-name="projectid">
    <div class="form-row">
        <label for="node-config-input-name"><i class="fa fa-bookmark"></i> Name</label>
        <input type="text" id="node-config-input-name">
    </div>
    <div class="form-row">
        <label for="node-config-input-projectid"><i class="fa fa-bookmark"></i> projectid</label>
        <input type="text" id="node-config-input-projectid">
    </div>
</script>

```

i try this but not work

---

<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: [31 March 2023 09:17 UTC](https://discourse.nodered.org/t/how-to-create-config-node-in-node-red/77101/11 "2023-03-31T09:17:05Z")

</div>

I had to strip out the `require` and the `input` message handling code in your .js file, but with rest of it as you provide it works:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/9/99afd200b654306b683d8d3dd2e505db6a53bfb6.png)

---

<div class="post-metadata">

### Author: ![natamongkol](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/natamongkol/32/78146_2.png) [@natamongkol](https://discourse.nodered.org/u/natamongkol)
#### Post date: [31 March 2023 09:17 UTC](https://discourse.nodered.org/t/how-to-create-config-node-in-node-red/77101/12 "2023-03-31T09:17:56Z")

</div>

i don't know why don't work for me but work for you

---

<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: [31 March 2023 09:26 UTC](https://discourse.nodered.org/t/how-to-create-config-node-in-node-red/77101/13 "2023-03-31T09:26:35Z")

</div>

In the browser's javascript console, can you run:

```auto
RED.nodes.getType('projectid')

```

and share the output?

---

<div class="post-metadata">

### Author: ![natamongkol](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/natamongkol/32/78146_2.png) [@natamongkol](https://discourse.nodered.org/u/natamongkol)
#### Post date: [31 March 2023 09:32 UTC](https://discourse.nodered.org/t/how-to-create-config-node-in-node-red/77101/14 "2023-03-31T09:32:44Z")

</div>

![a](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/a/8a7c89c9d9c26c6ba621e5e2e85a376b5bf2f871.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: [31 March 2023 09:35 UTC](https://discourse.nodered.org/t/how-to-create-config-node-in-node-red/77101/15 "2023-03-31T09:35:20Z")

</div>

Have you run that in a window with the Node-RED editor open?

---

<div class="post-metadata">

### Author: ![natamongkol](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/natamongkol/32/78146_2.png) [@natamongkol](https://discourse.nodered.org/u/natamongkol)
#### Post date: [31 March 2023 09:36 UTC](https://discourse.nodered.org/t/how-to-create-config-node-in-node-red/77101/16 "2023-03-31T09:36:11Z")

</div>

yes i open node-red tab and run `RED.nodes.getType('projectid')`

---

<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: [31 March 2023 09:36 UTC](https://discourse.nodered.org/t/how-to-create-config-node-in-node-red/77101/17 "2023-03-31T09:36:57Z")

</div>

Then I really don't understand... if you were in a window with the Node-RED editor loaded, then `RED` would definitely be defined.

---

<div class="post-metadata">

### Author: ![natamongkol](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/natamongkol/32/78146_2.png) [@natamongkol](https://discourse.nodered.org/u/natamongkol)
#### Post date: [31 March 2023 09:38 UTC](https://discourse.nodered.org/t/how-to-create-config-node-in-node-red/77101/18 "2023-03-31T09:38:06Z")

</div>

Should I also write the package.json file?

---

<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: [31 March 2023 09:40 UTC](https://discourse.nodered.org/t/how-to-create-config-node-in-node-red/77101/19 "2023-03-31T09:40:11Z")

</div>

Please show me a full screenshot of the browser window, with the node-red editor open, and the console with that error in

---

<div class="post-metadata">

### Author: ![natamongkol](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/natamongkol/32/78146_2.png) [@natamongkol](https://discourse.nodered.org/u/natamongkol)
#### Post date: [31 March 2023 09:46 UTC](https://discourse.nodered.org/t/how-to-create-config-node-in-node-red/77101/20 "2023-03-31T09:46:27Z")

</div>

![b](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/0/f04c1d45c44c3fce2782f9e86deaa8af51962f05.png)

it's node-red in Flowengine

 ![c](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/3/23815df936398244c28e9f31af3551355e143035.png)

[Next page](https://discourse.nodered.org/t/how-to-create-config-node-in-node-red/77101.md?page=2)
