Using Node.dll binary to execute JS in Win32 - node.js

As the title says, I would like to run a JS file from within my application. I dont want to create a node.exe process. Is there any sample example to start with?
Edit:
I plan to use standalone dll that comes with electron installer - https://www.npmjs.com/package/electron-installer-windows
or build it myself using electron instructions

If you just need run JavaScript in a Windows app, you can use ActiveScript instead.
Otherwise this doesn't seem like a programming question.

Related

How to get a path of the file name in node js

I'm working on desktop application using electronjs .I have name of the exe of application such as calculator,spotify,..etc . I want to launch those application from my electron application. In order to launch it I need path of those application exe. Is there any node js npm to ahcieve this or any electron library methods.
I am afraid if there is a package who does that. ( you can still google and see if you find anything).
How I would have approached this, I would save the executable path in environment variable and then run the program (you can google how to do that. typically you just spawn a process and pass arguments to it) based on the passed name.
thanks

How to run a js file from VSCode's builtin Node.js?

I need to run a js file from the Node.js that is builtin in the Electron which VSCode uses. Currently I am doing that by running a VSCode extension but there ought to be an easier way.
The code below should print the Electron version:
console.log(process.versions.electron)
VS Code does not expose functionality that lets users run arbitrary JS and this is unlikely to change. Using an extension is the correct approach

Angular + Electron app: query web API or DataBase according to deskop or web mode

I would like to build an app using Angular + Electron. My app should be able to run both on desktop and browser platforms. I'm considering to use angular-electron starter kit (but I'm open to other possibilities).
What concerns my is the way I read and write data. The data must be stored in a MySQL database. Ideally I would like to:
make the app call an api when NOT running on Electron (browser mode)
make the app query directly the mysql database when running on Electron (desktop mode)
I know I could check for window && window.process && window.process.type to let the app understand wheter running on Electron or not, however I'm a bit concerned about how to handle this. Also because I probably need to import node packages like mysqljs but ONLY in the desktop mode.
You can simply pass in different environment files in Angular during build this allow you to control the environment variables so that you can tell that it is a web app build or an electron app build.
https://angular.io/guide/build
EXTRA
But if you are importing binary packages this is where it gets tricky. I dont think there is a clean way for you to do conditional imports. I did not manage to find a way to do it cleanly and sort of maintained another repository for all my services that needs to import binary files.
To import the binary files you will also need to edit some webpack settings to tell angular to not compile/include the binary files during the build process so that you can use you librarys like mysqljs that require binary files. There is also some settings on the electron end to make binary files compatible for different platforms ie Windows, Mac , Linux. Basically it is really a pain to do it.
Link to how to edit webpack settings for angular 7+
https://github.com/manfredsteyer/ngx-build-plus
I will totally suggest you not to do it unless you really have a very good reason that you need to use these libraries.
EDIT 10/1/19
Okay I was referring to the MySqlJs but it seems like it does not have native modules modules. Native/binary modules basically means javascript code that relies on c++ compiled binaries(Or any native language like rust...).
For my case I was using the grpc modules which has a native dependency. Had to switch to grpc-web in the end.
I will add some footnotes here if you ever need them
https://electronjs.org/docs/tutorial/using-native-node-modules
Node.js / npm - anyway to tell if a package is pure JS or not?

How to run ElectronJs without a UI?

As well as a UI, I'd like users to have the option of passing in command line options to my tool and for it to output the response to the command line (eg manually or in cron).
Even without creating a window, the UI gets going (eg taskbar on the mac), and on a linux back-end server with no UI libraries it crashes completely.
Is there a way I can avoid having to ship two apps separately, and also more annoyingly using electron to package up one exe, and something like pkg for the other?
Thanks!
You can use a bundling tool like EncloseJS to wrap your Electron application. This would allow you to write a CLI interface. You would then need to move the code that does the actual work to a shared library that both Electron and your CLI can use. You could then introduce a --headless flag that would simply not start the Electron app, while omitting the flag would start the app as usual.

node js - How do I create build for commercial usage?

I am working on node js application and it is now ready to use. I want to make exe of this application so that it can be used for commercial usage.
Up to now I have used enclose module using which I have compiled the code of application but I have found some issues in that (app got crash on idle condition). App is running good without enclose or compiled code.
I have searched on google and found some alternate modules like JXcore, Node webkit and Electron etc. but JX core giving error same as in SO question.
In node web-kit, it's functionality is not looking suitable as we need its executable and some dll's along with our code, which makes our package bulky.
I have also tried jxcore. The main problem with the exe's and with modules that we use is their ability to work with native modules, in my case the Kinect.node module. This module cannot be compiled. We need a workaround to package only this along with our .exe file. Enclose provides this workaround in its inbuilt functionality.
Also looking a response from EncloseJS, which is actually run by just one person who gives further instructions upon purchase. A purchase is needed for commercial usage.
In case of Electron, It is supporting only Electron-based application source code. So If I choose this then I have to modify my application code.
So can any one suggest me what can I do to make exe file from node js code there?
Thank you!
I had the same issue before, the node js application close when running in background. now i am using process manager2 (pm2), it is working fine and if the application is crash due to any other reason it is automatically started again.
I have gotten my answer:
First, reason was DiskDB database, it was not compatible with the node webkit so that is why I was getting error of native modules.
Now I am using sqlite3 module for local database. It is better than DiskDB.
Second, One reason was free version of enclose, Paid version of Enclose JS module ignores the timeout issue which I was getting.
This way I have resolved my question.

Resources