Basically what I want to do is to incorporate node.js into my phoenix project and have it mount directly when I use mix phx.server. First of all I wanted to know if this is possible. And if so, where can I find out how to do it. My final intention in doing this is to be able to incorporate a checkout API for payments into my application, which does not have an implementation in Elixir.
If the API you want to call is well documented, then yes, and it’s pretty easy to do so. Just use Req to send HTTP(S) requests. You don’t even need to know what backend technology of the API you call, as long as it’s a JSON API over HTTP(S).
I’m interpreting this as you have some backend JavaScript code.
One approach is duplicating the API in Phoenix and calling the Node implementation behind the scenes. In this case the Req HTTP client can be used.
Another approach to use a reverse proxy. You could use something like nginx in front of both Elixir and Node, or if you prefer to manage everything in Elixir you can look into projects that do that. I’m not sure now which one is the best pick today, there are a few.
An orthogonal point is you can change your script aliases in mix.exs to start your node server along with Phoenix. Similarly, update Dockerfile and release scripts in production depending on your setup.
No, unless I am reading you wrong. Are there any programming languages that can freely embed each other? I mean OK, you can do so with Erlang and Elixir and there are other pairs as well like Java and Clojure (or any other JVM-living language) but to just get a collection of working HTTP endpoints and smack them inside an app made in another language is not supported out of the box pretty much anywhere.
You are better off just putting a reverse proxy like nginx or Caddy in front of both the Node.JS and Elixir app and have it decide which requests are served by which app.
…Or if you actually want to call the Node.JS app from Elixir, as in, do HTTP requests to it, then that’s a whole different story. Req
will sort you out there, easily.