View logs of electron-builder packaged AppX package - node.js

I've created an Electron app and I'm packaging it using Electron Builder. I'm using the AppX (Windows Store) format for Windows.
How can I view the app's logs i.e. console.logs from main node process?
I need to be able to view logs for the packaged version of the app as the app launches fine without AppX packaging, but fails with it.
On macOS, Linux and 'Windows with NSIS' instead of AppX, launching the app via the command line is sufficient to view logs
I've already tried launching AppX packages from the command line:
The only way to launch Windows Store apps from the command line is to follow these steps:
From here
Run explorer.exe shell:AppsFolder in cmd
Find the app, and create it's shortcut on the desktop
Open the shortcut's properties and copy the "Target" field
Run get-appxpackage > list.txt in PowerShell
Open the file (located in %USERPROFILE%)
Find and make a note of the PackageFamilyName and InstallLocation corresponding to the Target name copied earlier
Open the file AppxManifest.xml present in the InstallLocation
Search for "Executable=" in the file, make a note of the value of "Application Id" above the line containing "Executable=".
Run the command explorer.exe shell:appsFolder\<PackageFamilyName>!<Application Id>, substituting <PackageFamilyName> for the Package Family name noted earlier and <Application Id> for the Application Id noted earlier to run your app.
This works but doesn't actually connect node's stdout to the terminal

I don't know how you can see the log but the part where you launch the app from the command line seems like overcomplicated.
Here is a thread on how to launch an app from an appx/msix from the command line properly:
How to properly set AppExecutionAlias so the program could be launched from command line?

Related

How to create a Windows 10 batch file for launching local Node app?

I am trying to make a .bat file for running two separate apps locally, a React app and the Strapi service it depends on. My OS is Windows 10.
So far I came up with this:
echo Start React started
C:\Windows\System32\cmd.exe /k "C:\Program Files\nodejs\nodevars.bat"
cd "C:\Websites\React\react-template-app"
call npm start
It does launch a Node JS command prompt (line 2) and changes directory.
But it just will not run the npm start command. I tried several syntax variants.
When I type npm start in the command line opened by the script, it runs fine.
A batch file is processed by Windows command processor cmd.exe. The second command line starts one more cmd.exe to process the batch file nodevars.bat which defines multiple environment variables in context (memory) of this second command process. So the batch file npm.cmd being processed by first started cmd.exe cannot make use of the environment variables defined in environment of second command process. See also the long answer on What is the reason for "X" is not recognized as an internal or external command, operable program or batch file"?
I recommend not using a batch file for this task, but a shortcut file with file extension .lnk.
There is in Windows Start menu by default a shortcut to open a Command Prompt (file name on English Windows). Click with secondary (right) pointing device (mouse) button on this shortcut file and copy it. Then paste the shortcut file either on your Desktop or in a folder of the Start menu. Next click with secondary pointing device button on the pasted shortcut file and use Rename to change the file name, for example, to Start NPM.
Click with secondary pointing device button once more on the shortcut file for starting NPM and click in opened context menu on last menu item Properties.
There is opened a dialog window with several tabs. The displayed tab contains already the property Target which contains cmd.exe with full path. Append after cmd.exe a space and the following arguments:
/K "%ProgramFiles%\nodejs\nodevars.bat" & npm.cmd start
Next there is the property Start in which defines the current working directory for the executable started by Windows Explorer and defined with the property Target. Modify this property to:
C:\Websites\React\react-template-app
There is also the property Shortcut. By clicking into edit field and pressing a key combination like Ctrl+Alt+N, this key combination can be pressed later at any time with any window having currently the input focus to let Windows Explorer execute Target to start NPM with the configured properties.
There can be more properties configured to whatever is preferred like the icon, the font and font size for the console window, the background and text colors, the number of rows and columns (window height and width), etc.
Click finally on button OK and the shortcut file to start NPM is ready for usage. The shortcut file can be pinned on Windows task bar, but with having a Shortcut key combination defined for this shortcut file, it does not really matter in which folder the shortcut file is stored for execution.
nodevars which I presume is setting variables in the environment required for npm are being set in the context of the new window, so npm runs there with the variables set. The variables are not set in the context of the main batch, so it fails there.
Try simply call "C:\Program Files\nodejs\nodevars.bat" instead or ...cmd.exe...

Powershell script execution from node js fails

I have a list of Powershell scripts that we've developed for a system administration. These scripts are called/executed from a Node JS application using "child_process" module. Everything works fine on my laptop. After transferring Node JS application to Centos7 server I'm receiving errors like this one:
The term 'Connect-VIServer' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
I've checked Powershell execution policy - everything is set to Unrestricted. I can execute the same scripts from the command line without any error after I ssh to the server as a root user. The only difference I see is that Node JS application is running using a different user.
Found the problem - all modules were installed under /root/.local/share/powershell/Modules directory and nothing was installed under the user's profile that runs Node JS application. Copied all modules under app user directory /home/ndjs/.local/share/powershell/Modules/ and everything work now.

How to start "Xilinx SDK" from command line instead of from Vivado "File->Launch-SDK" Menu?

I'm wondering how to start "Xilinx SDK Eclipse GUI" (XSDK) directly from the command line?
Currently, I'm launching XSDK by first launching "vivado", and then going to the "File->Launch SDK" menu. However, this is a bit cumbersome to always open Vivado first, just to open "Xilinx SDK". What I want to do, is launch "Xilinx SDK" directly from my Git bash Shell under windows 10 and then open the previous project under "project_1.sdk" and to continue with what I was working on last time.
My Git Bash Setup:
#~/.bashrc:
export PATH=/c/Xilinx/Vivado/2017.3/bin:$PATH
export PATH=/c/Xilinx/SDK/2017.3/bin:$PATH
Then:
$ xsdk -workspace your_project_dir.sdk &
Also:
$ xsdk -h
Display Options:
-help
Help -- just display this message and quit.
-version
Display Version and quit.
-batch
SDK Tcl Batch Mode.
-wait
Wait for SDK to complete.
Options:
-workspace <Workspace location>
Specify the Workspace directory for SDK projects
-hwspec <hardware specification file>
Specify the XML file to load.
-bit <bitstream file>
Specify the Bitsteam file to use for programming FPGA
-bmm <bmm file>
Specify the BMM file to use for BRAM initialization
-batch -source <tcl script file>
Specify tcl Script file to executee all commands in SDK batch mode
{-lp <repository_path>}
Add <repository_path> to the list of Driver/OS/Library search directories.
-eclipseargs <eclipse arguments>
Any other arguments that should be passed to Eclipse.
This should follow all other SDK arguments.
-vmargs <java vm arguments>
Any other arguments that should be passed to Java VM.
This should follow all other SDK arguments.
Also useful:
SDK Command Line Batch Mode
The Eclipse/SDK can be launched in these two other ways
(1) Launch from the Vivado TCL Command Line:
Going from Vivado to SDK often has these steps
- File > Export (Hardware)
- File > Launch SDK
Each of these commands prints information in blue text in the Tcl Console.
Those commands can be copied into a tcl script and run from Tcl Console.
By default Tcl runs from this folder
C:\Users\WinUserName\AppData\Roaming\Xilinx\Vivado
If the script is placed there (e.g. zz1.tcl, or just zz1)
Then it can be run from the Tcl Console as
source zz1.tcl
That will execute the commands in zz1.tcl -> export hardware and launch the SDK
(2) Or, run Eclipse/SDK from Windows, then select the SDK folder:
The SDK can be run directly and can be found here:
C:\Xilinx\SDK\2019.1\bin\xsdk.bat
When it runs it will ask for a Workspace
Click [Browse] and navigate to the .SDK folder in the Vivado project
It will open and run as usual, without Vivado running, etc
Note: I have noticed that Vivado/SDK can be temperamental about how and when project folder contents are changed. Including if the SDK is launched and another SDK is already running in that folder. In some cases, the easiest recovery is to rename the ~corrupt SDK folder, create a new HelloWorld project, get HelloWorld running, and then update files into the new folder.

How to use Command Prompt after ng serve was compiled

In Angular 5, after creating project folder, installing Angular CLI, Node.js (all latest versions) and ng serve was compiled successfully through command prompt. Then I tried to use command prompt to install bootstrap. I could not control / use command prompt. What might be the cause and effect?
Command prompt stuck after compilation
There are simple ways:
If you use Command Prompt(Terminal), open another Command Prompt inside your project path.
If you use IDE like Visual Studio Code, open Terminal and then you can use Plus(+) sign for openning anothor Terminal like below image:
If you use IDE like WebStrom (Jetbrains IDE), first open IDE Terminal then make right click and select New Session and new terminal openning like below image:
There are couple of ways you can do that.
The official way of deployment of angular app.
Create a start.bat (if you are using windows) and write the ng serve --open command there. Now you can run this file which will internally run your angular app, using forever or pm2 npm modules.
If you do that these will demonise your process to run in background and your same command prompt becomes usable again.
Once the process is finished( compiled successfully), you would notice that the cmd -prompt newline doesn't show any directory and its blank.
This means that, you just have to open an another (new terminal), get to the right directory using "cd command "and implement your desired commands or operations again.
use ctrl + v it will ask weather to terminate say Y, cursor will go back

running a server file on node.js

I've been practicing with "hello world" examples of websockets and node.js server.
According to all those examples you create a html file (client) and a js file (server).
Before you run them, you have to run this on the command line (I use windows)
node nameOFtheServer.js
So, my question. If I close the command line window and open it again the client does not connect to the server. I have to run again the above code in the command line , manually, so the server will start again. Why is this happening? Is that normal? How can I fix it , so I dont have to run the same commands over and over again on the command line in order to start the js file (server) ?
Thanks
EDIT
OK, new facts, I just edited the question, highlighting the changes in Italics
When you close the terminal, everything that runs in it is killed. There are many solutions on both Linux and Windows systems, most of them create some sort of a service which then runs in the background.
Here are some possible solutions:
http://blog.nodejitsu.com/keep-a-nodejs-server-up-with-forever
https://github.com/indexzero/daemon.node
http://www.coretechnologies.com/products/AlwaysUp/Apps/RunNodeJSAsAService.html
http://coreybutler.github.io/node-windows/manual/#!/api/nodewindows.Service
Pick the one that is best for you.
Related question on StackOverflow:
How to run node.js app forever when console is closed?
First of all thanks Venemo for your anser. I tried use the forever module, but did not worked well, as you can see here.
So I decided to use nssm with node.js
I download the nssm and unzip it in the C:Program Files\path\to\nodejs. And then I opened Window's command window and typed C:\program files\path\to\nssm-2.16\win32 and then typed nssm.exe. You should see a "menu" how to install or remove services. And now type
"C:\Program Files\path\to\nssm.exe" install give-Your-Service-A-Name "C:\path\to\node.exe" \"C:Program Files\nodejs\path\to\yourServerFile.js"
Notice the \ before the "C:Program Files\nodejs\path\to\yourServerFile.js" it's not a typo, you should type it, is important, if you have spaces in your path, helps nssm to interpret correctly.
And that's it, now press CTRL+ALT+DEL, open the Services tab, and find give-Your-Service-A-Name , right click and select Start service. To check, open your client file that communicates with the yourServerFile.js, it should be working, without having to start the yourServerFile.js from command line.
(PS : I use nodejs 0.10.12 and nssm 2.16 on windows 7. The instructions above are a combination of this tutorial and this anser)

Resources