Node.js unresponsive until key press on console - node.js

I have a Node.js app, that runs on a Windows Server 2008. I'm facing a weird problem here.
My app does more than one async tasks. Sending data to socket.io, MySQL, HTTP connections, TCP connections etc.
My Node app becomes unresponsive especially on the socket.io end, and only starts responding back again after any key press on the console. Is this a known issue? Any bypasses around such a behavior?
Note: I am using console.log heavily to keep track of the current operation and errors in process.

I did a bit of a background check and came to the following conclusions.
The Powershell console on Windows Server 2008 goes on a 'pause' mode when clicked on it. It is released again if you click elsewhere.
http://www.vistax64.com/powershell/112032-script-pauses-when-you-click-powershell-text-window.html
If you notice, console.log is async. But console.warn and console.error are blocking. These are not async.
The console pause might block some/most part of the Node.js operations. Esp. as Socket.io at default debugging level will report with more than just console.log.

Solutions that other people have suggested didn't work for me, but using Cmder to start the script solved it. Definitely appears to be a console application problem, rather than a node.js problem.

I faced the same problem in a Windows Machine with my Node.js server running on PowerShell.
I solved it disabling Quick Edit Mode and Insert options in the Properties panel of PowerShell. It seems like pause the process when you click on the terminal with those two options enabled.
Hope this helps you, bro.

Related

Debug node.js web application that has been launched via a Gulp task

I have a web application that is written in node.js and gets started using a gulp command. When the application first starts, before the server is running, debug points may be hit in WebStorm (or in any IDE or command line tool). However, after the server is running and I go to the interface in my localhost I can no longer hit debug points inside the application. This is not being caused by client side code as the debug points are in server code.
I have read the answers that involve using the node-inspector and that has not solved my problem because of configuration files that are not getting read when starting the debugger in node inspector.
I'm a bit surprised that there is so little on here about this issue. Is it not a normal problem that other developers face? Thanks in advance for the help.
My workaround for this may not be sufficient for every case. I was modifying JavaScript files and didn't actually need the configuration files, after loading, to be able to test my changes. I did the following:
Wrote a line in my app.js file that set the variables I needed. (these would have been tasks ran in Gulp)
I then started the app as a Node.js app and was able to debug it as normal.
If any of my views had been updated, or anything else that was being managed by Gulp, then I could have simply stopped the server, started it again via the Gulp command, and then stopped again and restarted as a Node.js app.
This did not solve the issue in my OP but it was a good enough workaround to get debug points in the JavaScript.

linux or windows terminal over the web

I'm planing to make a web app which will allow you to have a Linux Terminal on a web page so that you can execute any command an get the response as if you were in front of your linux terminal.
I planed to use NodeJS as it is server side JavaScript, asynchronous and fast.
Also I saw this wich does exactly what i'm trying to do, I peeked in the source code, but didn't found something useful, I also analysed it with google chrome developer tools on the network tab, but there is absolutely nothing even while executing some commands and getting responses. How is this possible ? what technology do you think they used ?
So I wanted to get your advice, your experience in order to start it the right way.
I firstly decided to use NodeJS, but if there is another programming language or Framework more appropriate for this kind of application please let me know.
If you want a real terminal in the browser using node.js on the backend, you might give tty.js a try.
Alternatively you can use the pty.js module manually which is used by tty.js. Along with that, you could also use xterm for doing the browser-side terminal emulation.

How to debug Node.js based web application

I have been seeking solutions for debugging Node.js based web application from days. I had tried to debug with Eclipse + Chrome debugger plugin but failed, I posted the error in this session 'Failed to get tabs for debugging' when trying to debug NodeJs with chrome debugger for Eclipse, but could not find an answer.
However, as Node.js is so popular, I have no doubt that a lot developers have the solution for debugging Node.js server JavaScript code. I appretiate if you could share me your solution of setting up an IDE (edit and debug) for Node.js server JavaScript code, or at least how to debug it.
I would suggest using node-inspector. Here is a good tutorial for setting it up. It allows you to use a browser tab to look at your code, set breakpoints, and step through it. Additionally, you can start node with the flag --debug-brk and it will insert a break point on the first line, if you need to debug something that happens on startup.
There are several tools to debug a node application. A great ressource has been postet on Github recently.
A simple debugging setup might be just adding a breakpoint to your code and start node in debug mode like this:
Example code with use of debugger, a manual breakpoint.
app.get('/foo', function(req, res) {
var something = 123;
debugger; // execution stops if this point is reached
foo(something);
});
Start node in debug mode:
$ node debug app.js
Once you started the application in debug mode you use the application (e.g., navigate to the ressource with your browser) and once a breakpoint occurs, the execution stops and you have a debugger environment in your terminal.
Try to use Weinre (WEb INspector REmote). It's a node app help you debug UI, log for web app on devices.
It hope it can help you.

Weinre JS API onload/ready event

I'm using Weinre to debug an iPad App and was looking for a JS callback from Weinre that signals when Weinre has finished loading and e.g. it's safe to use its console object in my code.
I looked through the docs and the target-script.js that hooks Weinre into my page but couldn't find anything.
Any help would be appreciated.
I think by "safe to use the console" object, you mean, when will writing to the console object start writing to the remote console window. If so, that's a tough proposition, as your app might NEVER connect to a client debugger. Or the client debugger might connect, then disconnect, then connect, ... There would really need to be two events - weinreConnected and weinreDisconnected, or some such.
I didn't want to have to add new events to the system, but if there's a lot of interest, we can probably make it happen. Feel free to open a Jira issue for a new feature.

Console & Logging In Node.js From A HTTP interface

I have a difficult question that needs some answering, i have seen some projects where
the application runs a socket in a browser that has a console like format that the user can run for their node.js module...
If the actually calling a function or script is impossible from the web side,
i think it would be nifty to just see the console logs in the window.
If any advice could be shared, that would be amazing!
Thanks :)
Yes, there are several projects that do this. Weinre is very commonly used. You can look at its source code to see how it does it.
If I were to build it from scratch, I would utilize Socket.IO. Send the command, return the result.

Resources