What would be the best way of utilizing an npm (or other host language's library) library in my elixir otp app

I want to experiment with calling a javascript libraries’ functions to get a small subset of functionality to eventually plug into my OTP application. My first instinct is to create a script that installs the dependencies via npm and then just put the functions that I need in scripts that i can execute with System.cmd or another library like porcelain just execute the functions I need by passing node scripts/somefunction.js and getting the output to process. This would probably just work for strings but the library I’d like to use may return nested json objects or arrays. What would be the best way to

  1. Call the commands and get elixir datatype equivalents for the output
  2. Package it in a way that I just need a mix command to install it along with deps.get (the package, not node itself)

Jokes aside, take a look at Ports.

As for your points:

  1. Go for json or other serialization (which has more data types then a limited set JSON provides)
  2. You could do something similar to how phoenix /assets work, they end up in /priv which is added to the release.
3 Likes

Can use Deno: README — DenoEx v0.5.0

And there are these experiments:

1 Like