Nextcloud sharing files through IManager / Ishare

Hi,
I am trying to make a text file on calling of a function and use IManager to share it with another user on another nextcloud server using Federation share ID. The thing is if I am creating my own file on the run inside the function and want to share it with another person using Federation ID, how will I create the node here ?
My code is as follows :

public function share($type, $path, $initiator, $recipient, $permissions) : DataResponse{

            $content = "some text here";
            $fp = fopen($_SERVER['DOCUMENT_ROOT'] . "/myText.txt","wb");
            fwrite($fp,$content);
            fclose($fp);

            $userFolder = $_SERVER['DOCUMENT_ROOT'];
            $node = $userFolder->get("/myText");

    //        $node = $path;
            $share = $this->shareManager->newShare();
            $share->setShareType($type)
                    ->setSharedWith($recipient)
                    ->setSharedBy($initiator)
                    ->setNode($node)
                    ->setPermissions($permissions);
            $share = $this->shareManager->createShare($share);
            $share->setStatus(IShare::STATUS_ACCEPTED);
            $share = $this->shareManager->updateShare($share);

            return new Dataresponse($share);
    }

The call to this function is done correctly but I am unable to make a node here as it gives 500 internal error. Any help or guidance is appreciated. Thank you