A simple neu application that connects to a nodejs extension file. Started off with the default neu template in cli version 9.2.0, binary version 4.4.0, client version 3.3.0.
- Include
"extensions.*"in the"nativeAllowList"inside yourneutralino.config.jsonfile.
This is so you can callNeutralino.extensionmethods in your client-code. - Set the option
"enableExtensions": trueinside yourneutralino.config.jsonfile.
This is so your app tries to use websocket extensions when launched. - Set the option
"exportAuthInfo": trueinside yourneutralino.config.jsonfile.
This is what we read from in the extension file to get the necessary information for the websocket connection.
- Create a javascript file in the extensions folder in a folder name of your choice. The extensions folder is in the same directory as your
neutralino.config.jsonfile.
Check theextensions/my_nodejs_extension/main.jsfor our nodejs extension code. - Check the existing
resources/index.htmlfile for modifications to communicate with the extension. - Check the existing
resources/js/main.jsfile for modifications to communicate with the extension.
- Check the
neutralino.config.jsonfile for the"extensions"array which shows the format of how to call the extension. You'd realize I used a relative path, because I was never successful using the absolute path and including${NL_PATH}like specified in the docs.
Also notice that the"id"of our extension in this file matches theNL_EXTIDwe use in the nodejs extension file when connecting to the websocket, as well as theextensionIdin the javascript client file when dispatching (communicating with the extension folder).
- You may need to do error handling in your nodejs extension so that it does not crash.
- This nodejs extension uses
websocketanduuidto work. Ensure that you firstnpm iin thepackage.jsondirectory to import the necessarynode_modulesbefore testing your app. - Distribution: Not every computer may have nodejs installed, so you should bundle the nodejs application as an
.exewhen distributing. Don't forget to adjust your"command"in yourneutralino.config.jsonfile to launch that.exeinstead.
I have no idea how to bundle nodejs applications but someone suggested "bundling/packaging it with caxa" and "minifying/compressing with tools like upx". I have not explored much into it so I can't confirm it. - I removed unnecessary things from the
neutralino.config.jsonfile for this sample. Your configuration file may differ based on what you need for your own application.