Node server doesn't starts on it's own #2174
-
I've developed an app for Mac OS using Vue on frontend and Node on backend. I've packed NodeJS app with pkg npm package and have used binary as sidecar but Node server has to be started separately after building and installing the tauri app. Expected behaviour: NodeJS server should start before tauri app loads Can someone help me with this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey, in case you (or others) still have that "problem": You already mentioned that you have to start the server yourself, so you probably already know this, but just to be safe (and in case someone else stumbles upon this), here's an example how to tauri::Builder::default()
.setup(|app| {
tauri::async_runtime::spawn(async move {
let (mut rx, mut child) = tauri::api::process::Command::new_sidecar("express")
.expect("failed to setup 'express' sidecar")
.spawn()
.expect("failed to spawn packaged node");
});
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running application"); For more examples/instructions, see https://tauri.studio/en/docs/guides/bundler/sidecar and https://github.com/tauri-apps/tauri/tree/dev/examples/sidecar. |
Beta Was this translation helpful? Give feedback.
Hey, in case you (or others) still have that "problem":
The binary is not supposed to start on it's own. Imagine you have a sidecar binary which doesn't behave like a server and is supposed to be executed only in specific cases, auto-executing those would potentially be pretty bad.
You already mentioned that you have to start the server yourself, so you probably already know this, but just to be safe (and in case someone else stumbles upon this), here's an example how to
spawn
the server in thesetup
hook in rust: