# Calling Erlang from Javascript

**URL:** <https://erlangforums.com/t/calling-erlang-from-javascript/4416>\
**Category:** Questions / Help\
**Tags:** gen\_server, port, javascript\
**Created:** [January 23, 2025, 3:17pm UTC](https://erlangforums.com/t/calling-erlang-from-javascript/4416 "2025-01-23T15:17:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![scherrey](https://erlangforums.com/user_avatar/erlangforums.com/scherrey/32/242_2.png) [@scherrey](https://erlangforums.com/u/scherrey)\
**Post date:** [January 23, 2025, 3:17pm UTC](https://erlangforums.com/t/calling-erlang-from-javascript/4416/1 "2025-01-23T15:17:40Z")

</div>

We have a gen\_server that, right now, is only called from other Erlang applications. However now we have a client that wants to use the software but their code is written in Javascript using node.js. I’d prefer not to go through the overhead of building a web interface to our system. If we have to perhaps we’d make a websocket service but my preference would be to simply write them a Javascript client library that can talk directly to our system as if it were just another process similar to how Pyrlang works for Python/Erlang.

Is there a Javascript library out there that supports this? Has anyone had success doing this kind of intergration with a node.js app? Appreciate recommendations and experience stories.

---

<div class="post-metadata">

**Author:** ![asabil](https://erlangforums.com/user_avatar/erlangforums.com/asabil/32/381_2.png) [@asabil](https://erlangforums.com/u/asabil)\
**Post date:** [January 23, 2025, 3:25pm UTC](https://erlangforums.com/t/calling-erlang-from-javascript/4416/2 "2025-01-23T15:25:43Z")

</div>

Haven’t tried it, but could this work: [erlang-bindings - npm](https://www.npmjs.com/package/erlang-bindings) ?

---

<div class="post-metadata">

**Author:** ![scherrey](https://erlangforums.com/user_avatar/erlangforums.com/scherrey/32/242_2.png) [@scherrey](https://erlangforums.com/u/scherrey)\
**Post date:** [January 24, 2025, 11:31am UTC](https://erlangforums.com/t/calling-erlang-from-javascript/4416/3 "2025-01-24T11:31:31Z")

</div>

Looks promising. Will check it out and report back.

---

<div class="post-metadata">

**Author:** ![maxlapshin](https://erlangforums.com/user_avatar/erlangforums.com/maxlapshin/32/1593_2.png) [@maxlapshin](https://erlangforums.com/u/maxlapshin)\
**Post date:** [January 26, 2025, 6:31pm UTC](https://erlangforums.com/t/calling-erlang-from-javascript/4416/4 "2025-01-26T18:31:32Z")

</div>

> [@scherrey](#):
>
> I’d prefer not to go through the overhead of building a web interface to our system.

My experience with linking two languages is:

- calling lua from ObjectiveC
- calling luerl from erlang
- calling javascript from erlang
- calling C++ and python each other via Corba with mutual memory management

Result is simple: never again =) Calling HTTP or sending JSON-nd via stdout is something that really works when you need to connect two people. If you do something non-trivial, you will have lot of pain when you have to focus on something new and live your _interesting_ configuration to other people for support.

HTTP infrastructure costs almost nothing and is a basic standard nowadays.

---

<div class="post-metadata">

**Author:** ![scherrey](https://erlangforums.com/user_avatar/erlangforums.com/scherrey/32/242_2.png) [@scherrey](https://erlangforums.com/u/scherrey)\
**Post date:** [January 27, 2025, 2:56am UTC](https://erlangforums.com/t/calling-erlang-from-javascript/4416/5 "2025-01-27T02:56:12Z")

</div>

This is for a high-performance low-latency asynchronous event store so avoidance of overhead like http infrastructure has significant impact on the ultimate performance of the system. It’s cost isn’t nothing at our scale. HTTP isn’t very good at asynchronous calls which is what everyone of these is. Otherwise, completely agree that it’s a PITA. But this is one of those exceptions where it is worth it.

---

<div class="post-metadata">

**Author:** ![maxlapshin](https://erlangforums.com/user_avatar/erlangforums.com/maxlapshin/32/1593_2.png) [@maxlapshin](https://erlangforums.com/u/maxlapshin)\
**Post date:** [January 27, 2025, 6:23am UTC](https://erlangforums.com/t/calling-erlang-from-javascript/4416/6 "2025-01-27T06:23:26Z")

</div>

So you want to have some “scripting” considering that javascript is easier than erlang?

Can you share, what kind of logic can be written in another language, while maintaining such throughput and latency that http doesn’t fit?

This is a well known situation for me, our streaming server is designed for throughputs more than 1 million delivered frames per second, so there are nifs, etc, but it is interesting, what situation do you have.

---

<div class="post-metadata">

**Author:** ![Romansky42](https://erlangforums.com/user_avatar/erlangforums.com/romansky42/32/1960_2.png) [@Romansky42](https://erlangforums.com/u/Romansky42)\
**Post date:** [January 29, 2025, 9:07am UTC](https://erlangforums.com/t/calling-erlang-from-javascript/4416/7 "2025-01-29T09:07:15Z")

</div>

Tried node-erlang-bindings, but so far have only been able to establish connection with the Erlang node.  
`const mynode = new ErlangNode("node2", "persistence", "node1@127.0.0.1");`  
But, going by the examples in “test-napi.js”, haven’t yet be able to make gen\_server calls or RPC calls successfully…  
`let res = mynode.ex.GenServer.call(serverName, request);`  
Making the call the same way as shown in the only example results in this error:  
`TypeError: badrpc(undef): Erlang function Elixir.GenServer.call not found`  
I suppose that could be because I’m working with an Erlang node, and not Elixir, but I haven’t found a proper way to make a similar gen\_server call to Erlang with this library.

Similarly, I’ve tried calling one of the exported functions in our app using an RPC call:  
`res = mynode.rpc(atom("db_lib"), atom("list_databases"), [tuple("Admin123", "adm123")]);`  
“list\_databases” is an exported function in our “db\_lib” module, but the call results in this error:  
`TypeError: badrpc(function_clause): Erlang function db_lib.list_databases not found`

Most of the examples in node-erlang-bindings seem to be Elixir-specific, so would be grateful for any pointers on making these calls to Erlang, if anyone has experience with this library! 👌

At this point, I’m considering the option of implementing a websocket handler with Cowboy to communicate with JS.
