Results 1 to 19 of 19

Thread: [RESOLVED] Integrate Node.js to VB6 (or RC6)

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2020
    Posts
    314

    Resolved [RESOLVED] Integrate Node.js to VB6 (or RC6)

    There are many excellent libs on the Internet that are written in JavaScript or TypeScript, but it is difficult for us to use these libs directly in VB6, because the default running environment of these code libs is Node.js, not Web-Browser.

    I'd like to know if it is possible to integrate Node.js into VB6 (or RC6), just like RC6 WebView2-Binding (Edge-Chromium).

    In this way, I can call Node.js in VB6 to easily execute some JavaScript libs or TypeScript libs, for example:

    Code:
    sScript = "var esprima = require('esprima');" & _
                "var program = 'const answer = 42';" & -
                "esprima.tokenize(program);"
    
    vbNodeJS.Start
    
    sResult = vbNodeJS.ExecuteScript(sScript)
    Or

    Code:
    With vbNodeJS
        .Start
    
        .Cmd "var esprima = require('esprima');"
        .Cmd "var program = 'const answer = 42';"
        
        sResult = .Execute("esprima.tokenize(program);")
    End With
    Any help and suggestions would be greatly appreciated.
    Last edited by SearchingDataOnly; Apr 30th, 2021 at 12:47 PM.

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,321

    Re: Integrate Node.js to VB6 (or RC6)


  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2020
    Posts
    314

    Re: Integrate Node.js to VB6 (or RC6)

    Quote Originally Posted by Peter Swinkels View Post
    Hi Peter Swinkels, thank you for your reply.

    I know that Windows Script Control ActiveX control can execute some VBScript or JScript code snippets, and RC6 can also do similar work and do better. However, what I need is not to execute "JS code snippets", what I need is to execute "JS modules" (especially Node.js modules) or TypeScript modules. For example, execute a command such as "require('esprima')".

  4. #4
    PowerPoster
    Join Date
    Jun 2013
    Posts
    5,472

    Re: Integrate Node.js to VB6 (or RC6)

    NodeJS's primary "modus operandi" is as a WebServer -
    (started at the commandline, or simply "shelled" by a VB6-ClientApp).

    There's several npm modules one can install, to make the usage of the default httpServer module even more convenient.
    (one of the most used - also by me - is "express"):
    - just google for hello-world examples
    - if that works then google how to configure express, to receive and return json
    - then use the http51 Class, to perform your RPCs from VB6 (which against localhost have a quite good performance)


    HTH

    Olaf

  5. #5
    PowerPoster
    Join Date
    Feb 2006
    Posts
    22,295

    Re: Integrate Node.js to VB6 (or RC6)

    It would be a lot cleaner to stop using VB6 and just move to something like Electron, NodeGUI, Neutralinojs, etc. that wrap a GUI around the guts of Node.js itself.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2020
    Posts
    314

    Re: Integrate Node.js to VB6 (or RC6)

    Quote Originally Posted by dilettante View Post
    It would be a lot cleaner to stop using VB6 and just move to something like Electron, NodeGUI, Neutralinojs, etc. that wrap a GUI around the guts of Node.js itself.
    One of the most important reasons for continuing to use VB6 is VB6's powerful IDE (especially debugging features), which seems to be lacking in the javascript environment (such as node, electron, nodeGUI). I can't stand the way javascript is debugged in the browser at all.

    For me, without a powerful debugger, I can hardly write more than 100 lines of code.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2020
    Posts
    314

    Re: Integrate Node.js to VB6 (or RC6)

    Quote Originally Posted by Schmidt View Post
    NodeJS's primary "modus operandi" is as a WebServer -
    (started at the commandline, or simply "shelled" by a VB6-ClientApp).

    There's several npm modules one can install, to make the usage of the default httpServer module even more convenient.
    (one of the most used - also by me - is "express"):
    - just google for hello-world examples
    - if that works then google how to configure express, to receive and return json
    - then use the http51 Class, to perform your RPCs from VB6 (which against localhost have a quite good performance)


    HTH

    Olaf
    Thanks for your advice. I'd like to know if there is a way to further wrap express so that js modules can be called more conveniently in vb6? Like this:
    Code:
    With vbNodeJS
        .Start
    
        .Cmd "var esprima = require('esprima');"
        .Cmd "var program = 'const answer = 42';"
        
        sResult = .Execute("esprima.tokenize(program);")
    End With
    Last edited by SearchingDataOnly; May 4th, 2021 at 03:17 AM.

  8. #8
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    4,508

    Re: Integrate Node.js to VB6 (or RC6)

    One of the most important reasons for continuing to use VB6 is VB6's powerful IDE (especially debugging features), which seems to be lacking in the javascript environment (such as node, electron, nodeGUI). I can't stand the way javascript is debugged in the browser at all.

    For me, without a powerful debugger, I can hardly write more than 100 lines of code.
    But do you want to use the VB6 IDE to write, run and debug JavaScript??

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2020
    Posts
    314

    Re: Integrate Node.js to VB6 (or RC6)

    Quote Originally Posted by Arnoutdv View Post
    But do you want to use the VB6 IDE to write, run and debug JavaScript??
    No, I still run and debug JavaScript in the web-browser, which makes my development efficiency extremely low.

  10. #10
    PowerPoster
    Join Date
    Jun 2013
    Posts
    5,472

    Re: Integrate Node.js to VB6 (or RC6)

    Quote Originally Posted by SearchingDataOnly View Post
    No, I still run and debug JavaScript in the web-browser, which makes my development efficiency extremely low.
    There's ways to configure e.g. VSCode to allow NodeJS-debugging for that IDE.

    Not sure, why you are not investing this "one day of configuring-efforts, until debugging works in VSCode" -
    and instead invest months, to come up with a "kind of js-debugging in the VB6-ide".

    Anyways, to answer your prior question...

    node.exe can be "shelled" with different "startup-js-files"...
    (each of these files might represent a different "micro-service, which listens on a different port").

    So, why not name the service which knows your "esprima-tokenizer": esprima_3001.js

    Code:
    "use strict";
    
    var esprima = require("esprima")
    var express = require("express")
    
    var app = express()
        app.use(express.json()) // ensure auto-parsing of JSON-body-content
    
    if (app.listen(3001)) {
        console.log("esprima-microservice is listening on port 3001")
    } else {
        console.log("error: couldn't start listener on port 3001")
    }
    
    app.use((req, res) => { //generic route-handling
      var jsIn  = req.body
      var jsOut = esprima.tokenize(jsIn.code)
    
      res.json(jsOut)
    })
    The above is all you need, to encapsulate the esprima-module in a micro-service,
    which in its filename also describes the port it will be "listening on".

    For testing, I've shelled it on the commandline via: node esprima_3001.js

    As for VB-code... be creative yourself - but for a short test, this code:
    Code:
    Option Explicit
    
    Private Sub Form_Load()
      Dim jsIn As cCollection
      Set jsIn = New_c.JSONObject
          jsIn.Prop("code") = "const answer = 42"
          
      Debug.Print DoRPC("http://localhost:3001", jsIn)
    End Sub
    
    Private Function DoRPC(URL As String, Optional jsIn As cCollection) As String
      With CreateObject("WinHttp.WinHttpRequest.5.1")
          .Open "POST", URL, False
          .SetRequestHeader "content-type", "application/json"
     
        If jsIn Is Nothing Then .Send Else .Send jsIn.SerializeToJSONUTF8
    
        If .Status = 200 Then DoRPC = .ResponseText Else DoRPC = .Status & " " & .StatusText
      End With
    End Function
    ... produced this esprima-generated json-output:
    Code:
    [
      {"type":"Keyword","value":"const"},
      {"type":"Identifier","value":"answer"},
      {"type":"Punctuator","value":"="},
      {"type":"Numeric","value":"42"}
    ]
    HTH

    Olaf
    Last edited by Schmidt; May 5th, 2021 at 12:22 AM.

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2020
    Posts
    314

    Re: Integrate Node.js to VB6 (or RC6)

    Quote Originally Posted by Schmidt View Post
    There's ways to configure e.g. VSCode to allow NodeJS-debugging for that IDE.

    Not sure, why you are not investing this "one day of configuring-efforts, until debugging works in VSCode" -
    and instead invest months, to come up with a "kind of js-debugging in the VB6-ide".
    Now the latest version of VSCode can debug NodeJS without any configuration, which is great. But sometimes I need to debug js code in WebBrowser. Now, the biggest obstacle is that the require command in nodejs cannot be used in the browser. I don't know if requirejs can completely replace nodejs.require.

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2020
    Posts
    314

    Re: Integrate Node.js to VB6 (or RC6)

    Quote Originally Posted by Schmidt View Post
    node.exe can be "shelled" with different "startup-js-files"...
    (each of these files might represent a different "micro-service, which listens on a different port").

    So, why not name the service which knows your "esprima-tokenizer": esprima_3001.js

    Code:
    "use strict";
    
    var esprima = require("esprima")
    var express = require("express")
    
    var app = express()
        app.use(express.json()) // ensure auto-parsing of JSON-body-content
    
    if (app.listen(3001)) {
        console.log("esprima-microservice is listening on port 3001")
    } else {
        console.log("error: couldn't start listener on port 3001")
    }
    
    app.use((req, res) => { //generic route-handling
      var jsIn  = req.body
      var jsOut = esprima.tokenize(jsIn.code)
    
      res.json(jsOut)
    })
    The above is all you need, to encapsulate the esprima-module in a micro-service,
    which in its filename also describes the port it will be "listening on".

    For testing, I've shelled it on the commandline via: node esprima_3001.js

    As for VB-code... be creative yourself - but for a short test, this code:
    Code:
    Option Explicit
    
    Private Sub Form_Load()
      Dim jsIn As cCollection
      Set jsIn = New_c.JSONObject
          jsIn.Prop("code") = "const answer = 42"
          
      Debug.Print DoRPC("http://localhost:3001", jsIn)
    End Sub
    
    Private Function DoRPC(URL As String, Optional jsIn As cCollection) As String
      With CreateObject("WinHttp.WinHttpRequest.5.1")
          .Open "POST", URL, False
          .SetRequestHeader "content-type", "application/json"
     
        If jsIn Is Nothing Then .Send Else .Send jsIn.SerializeToJSONUTF8
    
        If .Status = 200 Then DoRPC = .ResponseText Else DoRPC = .Status & " " & .StatusText
      End With
    End Function
    ... produced this esprima-generated json-output:
    Code:
    [
      {"type":"Keyword","value":"const"},
      {"type":"Identifier","value":"answer"},
      {"type":"Punctuator","value":"="},
      {"type":"Numeric","value":"42"}
    ]
    HTH

    Olaf
    This is exactly what I need. Much appreciated.

    Before, RC5/RC6 built a bridge between VB6 and JS, now RC5/RC6 built a bridge between VB6 and NodeJS.

    In addition, I would like to ask one more question:

    I know that NodeJS and express can act as WebServer and display html pages. But the script in the html pages seems to be unable to use the NodeJS.require command. Is there a way to make the script in the html pages use the NodeJS.require command? Thanks.
    Last edited by SearchingDataOnly; May 5th, 2021 at 02:36 PM.

  13. #13
    PowerPoster
    Join Date
    Jun 2013
    Posts
    5,472

    Re: Integrate Node.js to VB6 (or RC6)

    Quote Originally Posted by SearchingDataOnly View Post
    I know that NodeJS and express can act as WebServer and display html pages.
    Not quite right.
    The Browser is the Client - and NodeJS the (Web)Server...
    (so we have separate Processes, which can only communicate via sockets ... aka "http(s)-based RPCs")

    The transfer-cycle (until you see an html-page in your Browser-Client) is:
    - Browser-RPC (based on http-protocol - via sockets, passing the initial URL, which describes a serverside resource)
    - NodeJS might answer this RPC (when it "knows" the received resource-URL) with an html-code-containing response
    - Browser receives the html-content from its "initially triggered RPC" - and renders (visualizes) the html-content

    Quote Originally Posted by SearchingDataOnly View Post
    But the script in the html pages seems to be unable to use the NodeJS.require command.
    As just described above... we have separated, different Processes (who don't really know about each other).
    The Browser runs its own js-Engine (which might be V8-based as well, in case of MS-Edge or Google-Chrome) -
    but it is still not the (enhanced about some "extras") V8-engine which runs in the NodeJS-process.

    In the same way as you wrote a little wrapper-routine, to do convenient RPCs in a VB6-Client,
    you'll have to write your own RPC-wrapper-function in the Browsers javascript-environment (google for "ajax-calls").

    Olaf

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2020
    Posts
    314

    Re: Integrate Node.js to VB6 (or RC6)

    Quote Originally Posted by Schmidt View Post
    Not quite right.
    The Browser is the Client - and NodeJS the (Web)Server...
    (so we have separate Processes, which can only communicate via sockets ... aka "http(s)-based RPCs")

    The transfer-cycle (until you see an html-page in your Browser-Client) is:
    - Browser-RPC (based on http-protocol - via sockets, passing the initial URL, which describes a serverside resource)
    - NodeJS might answer this RPC (when it "knows" the received resource-URL) with an html-code-containing response
    - Browser receives the html-content from its "initially triggered RPC" - and renders (visualizes) the html-content



    As just described above... we have separated, different Processes (who don't really know about each other).
    The Browser runs its own js-Engine (which might be V8-based as well, in case of MS-Edge or Google-Chrome) -
    but it is still not the (enhanced about some "extras") V8-engine which runs in the NodeJS-process.

    In the same way as you wrote a little wrapper-routine, to do convenient RPCs in a VB6-Client,
    you'll have to write your own RPC-wrapper-function in the Browsers javascript-environment (google for "ajax-calls").

    Olaf
    Very useful knowledge points. Thank you so much.

  15. #15
    Taking a Break
    Join Date
    Jan 2020
    Posts
    1,340

    Re: [RESOLVED] Integrate Node.js to VB6 (or RC6)

    v8 js engine.dll,Is it possible to compile it into a DLL and then call.The smallest version I have used is only 1.3 megabytes.

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2020
    Posts
    314

    Re: [RESOLVED] Integrate Node.js to VB6 (or RC6)

    Quote Originally Posted by xiaoyao View Post
    v8 js engine.dll,Is it possible to compile it into a DLL and then call.The smallest version I have used is only 1.3 megabytes.
    Could you give a simple example? Thanks.

    In addition, I would like to know whether the "v8 js engine.dll" you mentioned is the official version provided by Google or the version compiled by some programmers who tailored the v8 source code personally.

    If NodeJS can compile JavaScript into DLLs for VB6 to call, it will be very valuable.

  17. #17
    Taking a Break
    Join Date
    Jan 2020
    Posts
    1,340

    Re: [RESOLVED] Integrate Node.js to VB6 (or RC6)

    node.exe,Perhaps it is open source, very simple, we just need to wrap it a com DLL on it.
    Because there are many versions of Google, the earlier the smaller the version.In fact, its internal principle is a function.Just how to turn it into a DLL.
    Leave me a private mailbox, and I'll send it to you.

    Like Google Chrome, it's complicated to install and fills up my C drive every time.
    One Chinese changed him directly into a single DLL file.
    He also compiled the source code of IE6 in XP into a file.
    We know that we used to install ie9, IE11, may need to download half a day, and there is no way to coexist with multiple versions.
    Now it only takes one second to install IE6 on win10,if the Internet speed.
    And he edit for IE6 use V8 JS engine
    Last edited by xiaoyao; May 5th, 2021 at 09:53 PM.

  18. #18
    Taking a Break
    Join Date
    Jan 2020
    Posts
    1,340

    Re: [RESOLVED] Integrate Node.js to VB6 (or RC6)

    Open source, IE6 is installed on chromium V8, and the classic IE6 is about to be reborn from the ashes 2
    https://zhuanlan.zhihu.com/p/369676856

    https://www.vbforums.com/showthread....dll&highlight=

  19. #19
    Taking a Break
    Join Date
    Jan 2020
    Posts
    1,340

    Re: [RESOLVED] Integrate Node.js to VB6 (or RC6)

    Wrap all VB. Net libraries into a DLL or a function Wrap python as a DLL (this already exists)

    Making the Google kernel into a DLL (done) Freebasic compiler into a DLL, dynamic compilation of source.

    I am very interested in such packing behavior.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width