what you refer to is more generally known as a remote procedure call.
https://en.wikipedia.org/wiki/Remote_procedure_call
if you google for "rpc node" you will find some libraries that people have built, but the one I recommend is gRPC because it's backed by google and has good cross language support. Others might recommend apache thrift but I haven't used it. the other suggestion of expose an API endpoint is also a valid way to do this, but the code at the end does not look as clean.
Remote procedure call
In distributed computing, a remote procedure call (RPC) is when a computer program causes a procedure (subroutine) to execute in a different address space (commonly on another computer on a shared network), which is coded as if it were a normal (local) procedure call, without the programmer explicitly coding the details for the remote interaction. That is, the programmer writes essentially the same code whether the subroutine is local to the executing program, or remote. This is a form of client–server interaction (caller is client, executor is server), typically implemented via a request–response message-passing system. In the object-oriented programming paradigm, RPC calls are represented by remote method invocation (RMI).