n8n LabIntermediate
Extract Domain Name from URL using JavaScript in n8n
You have a full website URL and want to extract just the hostname (domain name).
Live Execution Simulator
Idle
π₯
Incoming Data
βοΈ
n8n Node
π―
Next Step
> Ready. Type your expression below and click "Check Answer" to run the node.
Incoming Payload / Data:
{
"website": "https://app.workflowexercise.com/dashboard/"
}
new URL($json.website).
βοΈ Your expression is executed against test data β any correct solution passes. +20 XP
β Solution & explanation
new URL($json.website).hostname
Output: app.workflowexercise.com
new URL() parses a string into its components. .hostname returns the domain without protocol, port or path; .host also includes the port, if there is one.π‘ Pro tip: Other useful properties: .pathname (/dashboard/), .searchParams.get('utm_source') for query parameters, and .origin.
Also accepted: host