Is there a way to start ElasticSearch simultaneously with nwjs?

31 views Asked by At

I want to integrate Elasticsearch into my NW.js application.

My current idea is to configure a JavaScript file in node-main that uses the Node.js API spawn to start the local Elasticsearch application.

child_process.spawn(
    resolve(`./cache/elasticsearch-8.11.4/bin/elasticsearch`),
    [],
    {stdio: 'inherit', shell: true, uid: process.getuid()}
);

I have a few issues. First, when starting, multiple warning windows pop up (see screenshots below). I don't know how to prevent them from showing.

enter image description here

enter image description here

Second, I want to encrypt Elasticsearch, but both the elasticsearch-reset-password and elasticsearch-setup-passwords commands seem to require interaction with the command line. Is there a way to set the password without interaction, directly to what I need?

Third, I want to limit Elasticsearch's maximum memory usage to 500 MB. I tried modifying -Xms500m/-Xmx500m in jvm.options, but it doesn't seem to have any effect. The memory usage still increases without limit until it reaches around 2 GB. How should I set this value?

1

There are 1 answers

0
The Jared Wilcurt On

Some ideas you could try:

  1. Concurrently/wait-on. Better for development than production.
    • If it is something that boots up relatively quickly but you want to wait for it to finish loading before the window appears.
    • For example, I use it to spin up my Vite dev server when working locally:
    • npm install --save concurrently wait-on
    • Then in my package.json:
      {
        "scripts": {
          "start": "concurrently -k npm:dev:web npm:dev:desktop",
          "dev:web": "vite --port 4175",
          "dev:desktop": "wait-on -c waitOnConfig.json http-get://localhost:4175 && nw ."
        }
      }
      
    • Then npm start to run the app locally.
    • In my case, dev:web spins up a local web server on port 4175.
    • dev:desktop will "wait" until it gets a 200 OK response from local host on that port, and then it will automatically run NW.js from the current directory
    • and npm start will run both of those at the same time, with -k meaning if either ends, the other is killed. So I can close the window and it will stop the server.
    • I do this for development, because the local server can take a few seconds to start up. I don't do this for production however.
  2. Use main and node-main in your package.json
    • "node-main": "index.js" - runs in the node context before a window is launched
    • "main": "http://localhost:4425" - will open a window pointed to this url
    • "node-remote": "http://localhost:4425" - Gives permission to this url to use Node.js commands from the DOM.
  3. Use a .js file as your main
    • "main": "index.js" - This will run a script, but will not create a window. From here you can run whatever Node.js code you want and then launch a new window when ready.
    • I generally only use this approach if I have multiple windows to launch and want to set up a window management system.
  4. Splash Screen
    • You can immediately launch a splash screen to inform the user that the app is loading.
    • Then in the background launch a separate hidden window in a new instance of NW.js (so it does not impact the splash screen), and communicate to the splash screen when it is done loading so the splash screen can close itself and the new window can be displayed.
    • There is a library you can use to make this easier: