Running node-webkit as node.js app - javascript

Is there any way to make node.js be host process for a node-webkit application?
I'm using Intellij IDEA for node.js development, and it have best debugger for node atm. But node-webkit presents its own nw.exe process, which can't be debugged by normal node.js environment. Other debug options (chrome devtools) don't match in effeciency with IDEA debug.
IDEA present some kind of nw debug support, but its very raw and works with many glitches and not works for many things.
So I want develop node-webkit app which starts under control of node.js process, like appjs was doing.

You could do that if you manage to launch nw.exe in debug mode using child_process.exec and make sure the line "Debugger listening on port [nnnnn]" is written to stderr, because according to https://youtrack.jetbrains.com/issue/WEB-1919#comment=27-556387
IDE parses it and can understand that a new debug session should be initialized and what debug port is.
That would be enough BUT the problem is:
child_process.exec will not return stderr until the child process ends and it does not provide a way to pipe it to the node.js host.
node-webkit only provide a --remote-debugging-port option to specify the port to open a devtools debugger; there's no option to start in debug mode (something like --debug or --debug-brk)

Related

How do I debug server and client simultaneously in WebStorm?

I have a node.js app that runs a server and sends index.html. The index.html interacts with the server.
I want to debug the complete app, but when I debug the app, WebStorm only debugs the server.
Is this even possible in WebStorm? If not, are there other tools that can do this?
In the Node.js run configuration, Browser/Live Edit tab, specify the URL of your server, tick both After launch and with JavaScript debugger checkboxes - client-side debugger will be launched once you start your node server with this configuration, so that you will be able to debug both simultaneously, using a single run configuration.
See also https://www.jetbrains.com/help/webstorm/debugging-javascript-in-chrome.html#debugging_js_on_external_web_server for some hints on debugging client-side code run in browser

sending console JS commands to an Electron app

I'm looking to automate an existing Electron app. It gives access to the Developer Tools, so I could just paste Javascript code into the console, but there must be a way to do this remotely, ideally using Node or from the Terminal?
I've seen this option for running Chrome : --remote-debugging-port=9222 ... that hints at a solution but I can't seem to get closer.
If you launch your Electron app with --remote-debugging-port=9222 then you will enable remote debugging via Chrome DevTools protocol. You can use a Chrome developer tools instance as a client, or use one of the clients here: https://github.com/ChromeDevTools/awesome-chrome-devtools#chrome-devtools-protocol
The debuggable Chrome instance will be running on localhost:9222. Which means as long as you are trying to debug from the same machine you are fine. However if you want to debug from a remote machine you need some additional setup.
Setup an SSH tunnel on the source machine:
ssh -L 0.0.0.0:9223:localhost:9222 localhost -N
This will accept incoming traffic on the 9223 port and route it to Chrome remote debugging.
Then on your client machine use the address: source-machine-ip:9223 to access the remote debugging.
Note: This may not work on Windows without additional SSH setup as SSH is not prepackaged with Windows.

Run node.js app remotely on WebStorm?

I have node.js installed on Vagrant and WebStorm access to a project on shared folder via VirtualBox.
Can I run node.js application on WebStorm and see the output on WebStorm (Terminal or SSH)? At the moment I have to keep switching to Putty to run it to see the output, its gets quite tiring.
Running Node.js applications remotely is not currently supported, please follow WEB-6136 for updates.
Debugging remote applications is possible (using Node.js Remote Debug run configuration - see https://confluence.jetbrains.com/display/WI/Running+and+debugging+Node.js+application#RunninganddebuggingNode.jsapplication-DebuggingNode.jsappthatrunsremotely). But you can't see the remote process output in WebStorm console, as Stdout of it is not accessible via debug protocol WebStorm uses for remote debugging. Related feature request: WEB-17013
This feature is available through ssh on Webstorm 2017.1
Scroll down to Configuring a remote Node.js interpreter on a host accessible through SSH connection in the link below:
https://www.jetbrains.com/help/webstorm/configuring-node-js-interpreters.html

How to browserify a Node.js WebSocket server?

Using examples from node-chromify I managed to run a Node.js Http server on a client side - inside a Chrome browser.
Then I tried to do exactly the same with a WebSocket server. Unfortunately I failed.
I think I tried most of the popular WebSocket libraries (npm modules) from Github.
While they work fine in configurations:
(a) both a WebSocket server and a WebSocket client are started from a Node command line
(b) the server runs from the command line and the client is included as a JavaScript in a html page (runs on a client side)
the scenario
(c) both the WebSocket server and the client running in a browser
is still unattainable for me so far.
During my attempts I tried the same approach by calling a command:
browserify server-ws.js -o bundle-server-ws.js
but when I included the generated bundle file into a html page I got always some critical errors regarding missing object definitions, etc.
In other words the above command seems not to bundle everything as the server code would expect during a runtime.
Should I use different switches/options during calling browserify?
Maybe it is not possible for browserify at all? For a client OK but with a server not...
I realize that migrating WebSocket stuff to the client side is much more complicated process than a regular npm module.
browserify v. 2.36.1
Node 0.10.22

Webstorm debugger for node.js

I'm trying to configure Webstorm for using the node.js' debugger.
I've set the enviroment and everything, the app is running fine with the run button, but with the debugger button it just hangs up writing only:
/usr/bin/node --debug-brk=52006 --debug-brk node.js
debugger listening on port 52006
and it doesn't work or writes anything on the output.
Any idea of what is missing? I've already installed node-inspector and everything.
EDIT:
After sometime that I run the code, I get:
Failed to open socket on port 52708, waiting 1000 ms before retrying
Problem solved with the help of JetBrains. In a few words, I used cluster creating child nodes that weren't connected to the debugger.
Full explanation here: https://intellij-support.jetbrains.com/tickets/13630

Categories

Resources