Node and/or DNS

56 views
Skip to first unread message

Bob Frankston

unread,
Jul 12, 2024, 9:17:15 AMJul 12
to DroidScript
As I get more things working, I have more questions. If this is better in discord, tell me where.

I need to do a DNS lookup. I couldn't find an app call for it, so I figured I could use Node. However, I'm not sure how to use a Node call from the browser app. Merely importing DNS didn't work.

Cemal

unread,
Jul 12, 2024, 2:27:20 PMJul 12
to DroidScript
You can run a node code and then communicate with it and get the result.


HTML/JS code
<html>
    <head>
        <meta name="viewport" content="width=device-width" />
        <script src="ds:/Sys/app.js"></script>
    </head>

    <body onload="app.Start()">
        <script>
            let node;

            function OnStart() {
                
node = app.CreateNode();
                node.SetOnOutput((msg) => { app.Alert(msg); });
                node.SetOnError((msg) => { app.Alert(msg, "Node Error"); });
                node.SetOnMessage((msg) => { app.Alert(msg); });
                node.SetOnReady(() => node.Run("node_script.js"));
            }
        </script>
    </body>
</html>


node_script.js
parent.SetOnMessage(msg => {
  parent.SendMessage(parseInt(msg) * 2)
});

Bob Frankston

unread,
Jul 12, 2024, 4:34:24 PMJul 12
to DroidScript
Thanks. I finally did find that in the documentation. I presume i can create a "node" subdirectory with its own tsconfig and then load the files from the "./node/" subdirectory.

Dave

unread,
Jul 13, 2024, 5:55:38 AMJul 13
to DroidScript
Note: You can use the node.Func( name, args... ) method to do RPC calls between your main app and the node script and use parent.Func( name, args...) in your node script to go the other way.

Or you could just switch your whole app to a 'Node Native' app and then you won't need to bother with the communication between main and node processes.  Although sometimes it can be useful to have two separate processes if you are doing a lot of work in the background.

Bob Frankston

unread,
Jul 13, 2024, 8:08:33 AMJul 13
to DroidScript
Thx. Will need to set aside time to try it.
Reply all
Reply to author
Forward
0 new messages