Printing PHP to node
That was a hell of a problem to solve. I had to rebuild my code. Instead of hooks I took a bit different approach and I tried a solution proposed by @IvanJaros but I wasn't able to get lazy builders to work. I found that in drupal 7 there was a hook_init that was called everytime but it got deprecated in 8.

The answers are EventSubscribers, using them you can assign any function you want to specific event i.e. loading a page. 
 Here's a great tutorial that intruduce you to that feature.

Here's my event code

    class MyEventSubscriber implements EventSubscriberInterface{

        public static function getSubscribedEvents(){
        // Its called when respond transfer ended
        $events[KernelEvents::TERMINATE][] = ['onRespond',28];
        return $events;
    }

  public function onRespond(FilterResponseEvent $event){ 
    $node = \Drupal::routeMatch()-&gt;getParameter('node');
    $user = \Drupal::currentUser();
    $name = $user-&gt;getUsername();

    $data = [];
    if(isset($node)&amp;&amp;isset($name)){
        $nodeType = $node-&gt;getType();
        switch($nodeType){
            case 'nodeType':
                $soap_response = new JSonGetter();
                $data = $soap_response -&gt; getUserData($name);
                echo('&lt;script&gt;var JSONarray = ' . print_r($faktury,1) . ';&lt;/script&gt;');
                break;
        }

    }
    }

}