Tutorial - Transform a website string into a domain

In this tutorial, you'll learn how to extract a domain name from a full website URL using Cargo. This skill is essential for streamlining workflows across various Cargo applications.


Pre-requisites

Before you begin

Make sure you have set up a sample data object that includes a website URL. This object will serve as the starting point for the expression you'll create in this tutorial.


Step 1

Identify the Website URL in the Start Node

The website URL is located within the Start node object. Use the following expression to capture it:


Capture the website URL with an expression

{{ nodes.start.website }}


Step 2

Remove the protocol

By this point, the expression will return the full website URL, such as https://getcargo.io/blog.

The goal, henceforth, is to isolate the domain name, removing both the protocol (https://) and any path beyond the domain name (e.g. /blog).


Remove protocol from the url with the split method

{{ nodes.start.website.split("//")[1] }}

Apply the split method to search for the // symbol, dividing the string into two parts. By selecting the second part with [1], we keep only the portion after the //.



Step 3

Remove the path

To isolate the domain name by keeping just the first part, use the split method again, this time targeting the / symbol that follows the domain name.


Final expression

{{ nodes.start.website.split("//")[1].split("/")[0] }}

Add this second split method to the end of the expression constructed in the previous step.



Step 4

Execute the node and review the output

Click the run button located in the right panel to process the expression.


If there's a syntax error, a red banner will display at the top of the left panel, similar to the following message: "nodes?.start?.website?.split(…) is not a function".

After running the expression, check the OUT tab for the result.


Outcome

Finish line

By this point, you have processed the string to return a clean domain name.