Rasbian on Raspberry Pi trying to run Electron app on startup - node.js

I'm trying to run a script on startup on my Raspberry Pi, I need to ultimatly run npm run start after everything has loaded in order to launch my Electron app. If I run this command in the terminal it works just fine, but for hours I've been trying to use a crontab, the RC Local and various other things.
My script doesn't run. I can verify that my rc local file is indeed running and my sh file is running, but Electron is never launched, what am I doing wrong?
I've got a command to execute a script that runs in rc.local which is:
sh '/home/pi/Desktop/cockpit-tv-monitor/start.sh'
The contents of start.sh is:
#!/bin/sh
# start-jammer.sh
# navigate to the home directory, then to this directory, then execute python script, then back home
cd /
cd home/pi/Desktop/cockpit-tv-monitor
echo "about to run npm run start" > /tmp/rc_test.txt
npm run start
I am getting the echo, but npm run start seems to never launch my electron app, and this command is essentially an alias which runs electron .
UPDATE 05/05 # 09:58
I've outputted the contents of npm run start to a simple text file using:
npm run start >> /tmp/start-output.txt > 2>&1
The error I'm getting is:
> cockpit-tv-monitor#1.0.0 start
> electron .
A JavaScript error occurred in the main process
Uncaught Exception:
Error: Failed to get 'appData' path
at App.c._setDefaultAppPaths (electron/js2c/browser_init.js:5:1300)
at Object.<anonymous> (electron/js2c/browser_init.js:197:2129)
at Object../lib/browser/init.ts (electron/js2c/browser_init.js:197:3540)
at __webpack_require__ (electron/js2c/browser_init.js:1:128)
at electron/js2c/browser_init.js:1:1200
at electron/js2c/browser_init.js:1:1267
at NativeModule.compileForInternalLoader (internal/bootstrap/loaders.js:283:7)
at NativeModule.compileForPublicLoader (internal/bootstrap/loaders.js:225:10)
at loadNativeModule (internal/modules/cjs/helpers.js:35:9)
at Module._load (internal/modules/cjs/loader.js:747:15)
/home/pi/Desktop/cockpit-tv-monitor/node_modules/electron/dist/electron exited with signal SIGSEGV
This is even after adding a delay before running npm run start of 30s, still get the error.

did you try running it from
/home/pi/.xinitrc
just create that file, and insert
cd /home/pi/Desktop/cockpit-tv-monitor && npm run start &
reboot and hope the best.

The error seems to be Failed to get 'appData' path, which is probably an OS related thing.
appData is where Electron saves its cookies and other electron runtime related items. This might mean that your OS doesn't have the proper directory that electron can save to.
For linux (e.g. Raspberry Pi), it looks for two things either and environment variable called $XDG_CONFIG_HOME or something with this file ~/.config.
You can output the value of either by
echo $XDG_CONFIG_HOME
or
cat ~/.config
to see if a paths exist.
If neither work you can update your npm start script and pass an environment variable on start like XDG_CONFIG_HOME="~/usr/electron/myapp" && electron . that adds the environment variable before boot with a directory.

Related

Autostart a node.js script using init.d in Debian

I have a little node application on a server (node mailer) that I run by going to its source folder and executing npm start. I figured the best way to run this automatically would be to create a my_script.sh file and drop it in the init.d directory of my debian box. Inside the file (below the !#/bin/bash line), the code to execute is
'/opt/mycode/source/npm start'
I save the line to the .sh file and restarted the machine, but so far haven't got it to work. My question is: is this even how you start a script like this (using that command and an .sh file)? It does start normally when I do it manually (when I navigate to it and run npm start in the terminal). I included the single quotes around it because of the space between npm start. Also, if I want to verify that it worked, which process would I look for other than just pinging my smtp mailer? Finally, I know I need to run:
update-rc.d my_script.sh defaults
but I was also confused at to whether I had done this correctly either (is it just the name of the file that goes there or the file plus the extension)?
The script that you leave on the init.d folder should not have any extension and should have functions to start, stop and get the status of the service (your application).
I'll leave a link with an example as well as with some basis in order to build the Linux service script.
I would suggest reloading the daemon with systemctl daemon-reload in order to refresh the Linux service files once you add a new one.

How can I run a node app from the command line and return control?

I run a angular app like this:
npm run server-java
From a terminal window.
The server starts, but I want it to give back the shell prompt.
I want the shell prompt back while it runs.
You can use tools like pm2 or forever to start your nodejs app as a background process. Usually used for production setup.
Another option is:
npm run server-java > /dev/null 2>&1 &
You will get back to the terminal, but then you have to kill process manually by id when you don't need it.

How to execute two commands in cmd (node and npm) and then start a browser when localhost is available

I got a task to create a powershell or a batch file on Windows which should, in sequence, start a "node file.js", then call a "npm start" command in another directory and then launch a browser to localhost:3000.
The problem is that I can not get the exact time when to launch the browser at the very end. I tried to concatenate commands with & and && (How to run two commands in one line in Windows CMD?) but the browser got launched before the scripts reach the end in the first case, never in the second case. I guess cmd simply can't understand when node or npm commands are finished to be executed.
Does anybody have experience with this particular task?

Running Karma from TeamCity

Does anyone know how you would run the following command within TeamCity? (the command is normally ran in a Node.js command window)..."Karma start karma.conf.js". I have successfully installed Nodejs on the TeamCity server. I have then successfully installed Karma on the same server (using npm install -g karma).
In TeamCity, my build step has "Runner type = Command Line", and the Custom Script is set to "FULLPATHOFKARMAEXE\karma.cmd start FULLPATHOFKARMACONFIGFILE/kara.conf.js"
When i run TeamCity, it comes back with the error "node is not recognized as an internal or external command"
Anyone know the step-by step process of running Karma within TeamCity?
In your case, the Karma installation seems to be OK, but your TeamCity agent process is unable to resolve the path to Node.exe (it's installation folder is missing from the %PATH% variable).
First verify the NodeJS installation by opening a Commandline window on the agent machine, type node and press enter:
c:> node
>
If the result in your Command window is a >-prompt, you might solve your problems by restarting the build agent.
If the result in your Command window is some error message saying "node is not recognized as an internal or external command", you need to add the NodeJS installation folder to the %PATH% variable, and restart the build agent.
You can, of course, just change the %PATH% for your build agent service by running a initialization script included in the NodeJS installtion folder in your build step. Depending on where your NodeJS installastion is, your custom script might look like this:
"C:\Program Files (x86)\nodejs\nodevars.bat"
"FULLPATHOFKARMAEXE\karma.cmd start FULLPATHOFKARMACONFIGFILE/kara.conf.js"

I can't run test with "vows test/*" command on windows. How to use it? node.js

I've installed vows as module of my project and I've added the path "node_modules\vows\bin" to my environment path variable of windows vista.
note: I've also renamed "node_modules\vows\bin\vows" to vows.exe, because without the extension I get this error: 'vows' is not recognized as an internal or external command,
operable program or batch file.
Now wherever I put "vows" in my cmd in windows nothing happens, I cd into my test folder and I run "vows myFirstTest.js" and nothing happens. (when I say nothing happens my cursor in cmd is going to the top and then return to it's original position and it's doing this forever, therefore each time I try a vows command in cmd I have to close the cmd to run another command).
What I'm doing bad?
thanks
NPM is great at globally installing packages and making the executable for each operating system (UNIX-ish + Windows), so proceed with the following:
npm install -g vows

Resources