Elixir/Phoenix app: How to run "node" command using System.cmd("node", ...) on a Fly machine?

I’ve got a Elixir/Phoenix app that I just deployed to Fly. On my local machine I have a line of code that runs a node file like this:

{array_as_string, code1} = System.cmd("node", ["/app/assets/js/getTradingGameResult.js", Integer.to_string(current_price)])

and it works fine on local but on my Fly machine the “node” command is not available and I get the following error:

2024-03-24T04:47:32Z app[e286de6ae72208] waw [info]** (stop) :enoent
2024-03-24T04:47:32Z app[e286de6ae72208] waw [info]    (elixir 1.15.6) lib/system.ex:1092: System.cmd("node", ["/app/assets/js/getTradingGameResult.js", "50000"], [])
iex(appname-01HSQCFQM7WPG41HDXQ362JTY0@fdaa:0:9cc8:a7b:c8:9efd:3144:2)4> System.find_executable("node")
nil
iex(appname-01HSQCFQM7WPG41HDXQ362JTY0@fdaa:0:9cc8:a7b:c8:9efd:3144:2)3> File.exists?("/app/assets/js/getTradingGameResult.js")
true

Node is installed on my Fly machine. I get the same error when trying to run the command in iex via fly ssh console, How can I access the node command on Fly?

Can you try looking into where’s the executable using which node on your fly ssh console session? Maybe its an issue with your PATH and you could solve that by either adding it to your PATH on your Dockerfile or just suing System.cmd("/path/to/node", []) in prod.

Fly email support guy just fixed it, I needed to add nodejs to the runner image in my Dockerfile like this:

# start a new build stage so that the final image will only contain
# the compiled release and other runtime necessities
FROM ${RUNNER_IMAGE}
RUN apt-get update -y && apt-get install -y libstdc++6 openssl libncurses5 locales file nodejs \
&& apt-get clean && rm -f /var/lib/apt/lists/*_*
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.