Node properties with default expression

Hey, how are you doing?

I’ve created a custom node. I want some properties of this node to have default expression.
Right now when defining a property I did this:

displayName: “Type”,
name: “type”,
type: “string”,
default: “{{$node[“Webhook”].json[“body”][“type”]}}”

And then in execute function I use “evaluateExpression” function and everything works well, but this node looks like this:

But I need a way to implement this behaviour like this:

This one evaluate the expression before execute. The property has an expression and you can remove it as well. (It’s not a string just like the first one)

Is there any way for doing this ?

Yes, if you add an equal sign in front of it =. That tells n8n internally that a field contains an expression.

So you would set it to:

  default: '={{$node["Webhook"].json["body"]["type"]}}'

Wow Great,
Thank you. What an amazing feature!

1 Like

Glad to hear that it helped!

Have fun!

1 Like