How do I get the base path? I want to use the base path in a Drupal 8 template file. I tried the following, but I don't get the correct result.

{{ app.request.baseUrl  }}

{{base_path}}


What I need is the absolute path to the node {{ app.request.baseUrl  }}/{{ url }}.

One solution I found is putting  this code in a preprocess hook, and pass it to the theme. 

 $host = \Drupal::request()-&gt;getHost(); 
$response = \Drupal::httpClient()


I am looking for a better solution. What could should I use instead of the one I am using?
You can use url() to generate a base url to any route in Drupal. You can supply the &lt;front&gt; route which, in effect, will be your base URL.

{{ url('&lt;front&gt;') }}


But, render it first if you're concatenating it:

{{ url('&lt;front&gt;')|render ~ file_url('public://image.jpg') }}


For example:

{{ url('&lt;front&gt;') ~ file_url('public://image.jpg') }}
# Outputs: "Array/sites/all/default/files/image.jpg"

{{ url('&lt;front&gt;')|render ~ file_url('public://image.jpg') }}
# Outputs: "http://example.com/sites/all/default/files/image.jpg"