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.json
file.
This is so you can callNeutralino.extension
methods in your client-code. - Set the option
"enableExtensions": true
inside yourneutralino.config.json
file.
This is so your app tries to use websocket extensions when launched. - Set the option
"exportAuthInfo": true
inside yourneutralino.config.json
file.
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.json
file.
Check theextensions/my_nodejs_extension/main.js
for our nodejs extension code. - Check the existing
resources/index.html
file for modifications to communicate with the extension. - Check the existing
resources/js/main.js
file for modifications to communicate with the extension.
- Check the
neutralino.config.json
file 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_EXTID
we use in the nodejs extension file when connecting to the websocket, as well as theextensionId
in 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
websocket
anduuid
to work. Ensure that you firstnpm i
in thepackage.json
directory to import the necessarynode_modules
before testing your app. - Distribution: Not every computer may have nodejs installed, so you should bundle the nodejs application as an
.exe
when distributing. Don't forget to adjust your"command"
in yourneutralino.config.json
file to launch that.exe
instead.
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.json
file for this sample. Your configuration file may differ based on what you need for your own application.