Skip to content

Build instructions, console mode, require calls #1

@euglv

Description

@euglv

Hello,
thank you for work and for great example how to embed node.js into delphi application.
Here https://github.com/ivere27/toby we can find instructions how to build c++ application that embeds node.js.
But there are no instructions how to build tobynode.dll for use with Delphi. It may be hard for some one from Delphi world to build something in Visual Studio.
By the way, main page of this repository suggest downloading debug version of tobynode.dll:
https://github.com/ivere27/archive/tree/master/tobynode/node_v6.10.0_x_toby_v0.1.5_x86_debug
This dll works only if Visual Studio is installed. Or you need to collect and copy to application folder some dll-s from the debug version of visual studio redistributable package.
This solution https://github.com/ivere27/toby/tree/master/vc_tobynode has only debug configuration setup. When I tell Visual Studio to build release version of tobynode.dll - it doesn't builds, because release configuration is not set (folders, linker and compiler settings).
I wanted to build release and optimized version of tobynode.dll that doesn't require installing C++ redistributable packages.
After lots of hours finally I managed to build release version of tobynode.dll, but it was only 53 kb and required node.dll and redistributable package.
Also I figured out that node.js 6 and above does not support Windows XP, but my delphi application needs WinXP support.
The good news is that tobynode support node.js 5.11 and node.js 5.11 support Windows XP!
Finally I managed to build tobynode.dll with node.js 5.11 inside, it is almost 9 Mb in size. I tested it on Windows XP SP3 without any redistributable packages, and it works.
I think it will be good to share this dll with others:
tobynode.zip - release version, node.js 5.11
Here is solution with release configuration to build this dll:
vc_tobynode.zip
Folder structure should be the same as described here for building C++ sample.
Unsure if I configured this solution correctly, because I am not familiar with C++, may be it misses some parts, but all node.js features I tested - worked.

I have some additional questions, unsure if I should create separate issue for each or not.

  1. TobyPascal.pas statically links tobynode.dll, because of this tobynode.dll is loaded early when program starts. Because of this delphi application has to be configured as console application. If delphi application is not console - node.js core code throws errors. Allocating console before creating TToby class does not help, console should be allocated before tobynode.dll loads. So the question is:
    How to use tobynode.dll not in console application?
    Core node.js code throws errors when there are no stdout or stderr even if console.log(...) is not called from javascript. For example node.js source file node\lib\net.js has this code:
    if (this !== process.stderr)
    This code only checks if current stream is not stderr, nothing was going to be logged, but code is failing not in console application.
    I suggest modifying TToby class to load tobynode.dll dynamically, so we can setup stdout and stderr pipes before loading tobynode.dll.
  2. Is there any way to intercept javascript require call? I want to embed some third party node modules to my application, but I do not want them to be stored in node_modules folder in application directory. I want to store third-party modules that are loaded through require call as resources of main executable (or at least inside tobynode.dll). Can I achieve this without modifying node.js sources and rebuilding tobynode.dll when I need to embed some new module?
  3. How can I unload and reload tobynode.dll without restarting Delphi application? (For example in case some runtime error in .js code)

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions