Building Electron with my own module - node.js

I am learning building Node modules and packaging it with Electron. I've successfully built an module out of a CPP file and can run it with node. However, to run it with Electron I need to rebuild Electron. There are instructions out there, for example:
https://github.com/electron/electron/blob/v0.37.2/docs/tutorial/using-native-node-modules.md#using-native-node-modules
https://github.com/electron/electron/issues/2330
Here I have an addon.node file after running node-gyp build. I can reference it in the node application from anywhere: var addon = require('.Release\addon'); and it works fine. However, when I build Electron with it I don't understand where to put the .node file so that it is used in the build. Before I run node_modules\.bin\electron-rebuild (see bullet point 1 link above) where should I put the addon.node file? Is it right to say that before I even test it withing Electron (with console.log or something) I need to run electron-rebuild. Is there a step that I missing that I need to take from having the addon.node file to starting to build it into Electron?
Thank you.

Related

Compiling a Node.js (github action) into a single file using `#zeit/ncc`

I'am trying to compile a Node.js package (github action) into single file using #zeit/ncc NPM package, but some dependencies don't get copied to dist directory.
For example my package depends on 7z-min and nightmare NPM packages. Running ncc build index.js build single file successfully and copies 7z binaries for each platform correctly but nightmare electron binaries don't get copied. Only a file called path.txt containing dist/electron.exe.
When running my github action it fail to find electron executable.
Most probably you might have not imported the package in the JS file.

Making node.js code to a executable file in MacOS

I have a nodejs app app.js which I'm able to execute with help of the command line tool (changing to the direction of the app and executing the command
node app.js
before that the application is installed with npm install). To make it easier in the daily use i would like to make the app executable, both parts, the installation as well as the trigger of the app.
The app is for generating a small report, I already tried it with a script where I saved the command node app.js.
You might use pkg.
This command line interface enables you to package your Node.js project into an executable that can be run even on devices without Node.js installed.

How to build native nodejs modules for launchui?

I'm building an app using proton-native.
it uses native modules written in C++, for example, keytar.
Proton-native uses a tool named launchui to package nodejs app as an executable. It's basically simple wrapper for nodejs with the following structure on windows:
- myapp.exe
- node.dll
- app/
- - main.js
- - node_modules/
- - - - keytar/
Native modules (node addons) does not work by default for such constructions because node-gyp tool links them against node.exe.
The usual approach is to run something like electron-rebuild, which would compile native modules to a version of node incorporated by electronjs.
However, In case of launchui there are no tools for that yet.
Could someone skilled in node-gyp or C++ linking explain what whould be the best approach to properly re-build native modules for launchui? I keep getting The specified procedure could not be found after running electron-rebuild and trying to run the app.
I have used dependencywalker to analyze current dependencies of the keytar.node and it shows that it depends on node.exe, however it should depend on node.dll.

How to make a Nodejs distributable command line application

I'm making a command line application with commander, inquirer and nightwatch as top dependencies. The main purpose of the app is for automation and testing.. Is there any way i can make this distributable instead of publishing it as npm package. I want the same functionality as those cli made with python, where it can be setup, and run on a target machine. is this possible? Thank you
Here are two open source projects (PKG and Nexe) that enable you to package your Node.js project into an executable:
https://github.com/zeit/pkg/blob/master/README.md
Or
https://github.com/nexe/nexe/blob/dev/README.md
You can use either one to make an executable of your project.

Builded electron application load node module on runtime

I have a problem with an app based on electron. When I build my electron app with electron-builder it produces a appname.exe file which has probably the html/js/css sources in the exe file or another one in the produced directory. When I try to require a node_module from the developer console in the builded app, the module is not getting found :(.
The app is looking in a file called electron.asar liked it seems for the module. I don't really understand this because over modules are getting found, otherwise, the app would not be able to start anyhow.
Maybe one of you guy's have already faced that problem?
yes, the module needs to be listed in the dependencies section in the package.json to be found in the built electron app.

Resources