NodeJS program memory usage won't go down - javascript

I was writing a nodejs program but it has some problems, I created an issue in the iojs github but the guys said that it's likely a problem in my code and I should try posting it here.
I'm new to javascript and server-side javascript.
This is a simplified version of my real code that is way bigger.
I tried searching everywhere for a solution for this, tried not using event emitter and everything even tried manually nulling almost everything that would not be used anymore but it won't help at all.
This small snippet "leak" the same way my original code does.
Steps to reproduce:
Download: these three scripts
socket.js: https : //gist.github.com/dumpsters/11dab119e996b802a824)
client.js: https : //gist.github.com/dumpsters/17566cce2777470218e4)
server.js: https : //gist.github.com/dumpsters/860bac40048db45e0424)
Execute server.js
Execute client.js
Let client.js run for a while while checking server.js memory usage in the title bar
Close client.js
Check server.js memory usage
server.js memory usage will either stay the same or even increase and won't ever go down.
Tried with latest stable iojs version and latest nightly version, also tried with stable nodejs.
Any clue on why this happens?

Related

Serving a project in Ember using `ember s` triggers file changed

So, I am serving an Ember using ember s command. Even though I do not make any changes to the code I keep seeing the entry file changed <fileName> in the server startup log, this makes the server start process really slow. I am using Windows 11, however this happened in windows 10 also, ember-cli version 3.8.3.
There is an issue raised in github with no solution - https://github.com/ember-cli/ember-cli/issues/9055. This is the only mention of this issue I could find.
Hope someone has a solution to this.

Quirk while debugging Javascript app in Webstorm 8

I'm trying to debug an AngularJS app in Chrome (with the Jetbrains extension) within Webstorm 8. It's working just fine, but the only naggy thing is that the actual file that has breakpoints in it doesn't get debugged, but a readonly copy that reads as the full url of the file is (see screenshot). It works, but I cannot edit the readonly file while moving from line to line.
edit: plus, the IDE usually shows an outdated version of my JS file and I have to manually refresh it to see the correct one.
The Webstorm Run/Debug config for Javascript is really straight forward, basically just the URL to the app.
Does anyone knows how to avoid this?
Cheers
The short answer is: you can't
The longer answer is, the computer is not running the code that you see on the screen, that's just what the debugger is showing you. The computer is actually running optimized, non-human-readable Javascript bytecode, which is created when you start your JS program, after syntax is checked, namespaces are created and memory is allocated for variables etc. You can't edit that bytecode by writing JS code directly, at least not with any debugger I know of (and I'm fairly certain you can't with Webstorm specifically; I use PHPStorm and its Javascript debugger).
Such problems usually mean that remote files are not correctly mapped to local ('remote URL' not correctly set for local files in Run configuration), so the debugger can't map the files being executed to your actual sources. I'm not sure what your application looks like... But, as Angular apps structure is more or less standard, I can suggest mapping the 'app' folder to 'http://localhost:9000' in javascript debug run configuration you are using to debug your angular code

How to debug Nodejs/Expressjs(MEAN stack) [duplicate]

I'm looking for effective way for step-by-step debugging NodeJS server code. At this moment I use dozens of console.log()'s and it's extremely hard. The perfect tool is one that would allow me to check the values of every variable in stack and trace my program line by line. Prefered OS = MacOS/Linux. Is it possible?
Basically, Node.js is built on top of V8, so its debugging capabilities are also built on top of V8's debugging capabilities.
V8 has an included debugger which can be accessed via TCP on port 5858.
So basically all you need is a frontend which is able to connect to port 5858 and talk V8's debugging protocol.
One option is to use node-inspector which basically provides a debugging UI in your browser. Unfortunately, it does only work with Google Chrome and Apple Safari (which for me is no problem, but there may be others ;-)).
Another option is to use a plugin for Eclipse.
And, last but not least, the built-in debugger of Node.js (which always reminds me of MS-DOS's edlin) is also just a front-end for this TCP debugger, just a built-in one.
And of course, there are much more options ... these three were just the first three ones that came to my mind ;-)
How about this?
You can try to test for Nodeclipse version 0.2.0 beta.
http://www.tomotaro1065.com/nodeclipse/
It will help you to debug node apps easily.
GENERATING OF EXPRESS PROJECT
Select the [File]-[New]-[Project] menu.
Select [Node]-[Express Project], and push [Next] button.
Enter [Project name], and push [Finish] button.
DEBUGGING
Open the JavaScript source files that you want to set breakpoints.
Double-click on the ruler at the left end of the line you want to set a breakpoint.
If you want to remove a breakpoint, double-click on the ruler again.
Select the main source file of Node Application on the Project Explorer,
open the context menu by right-clicking,
select the [Debug As]-[Node Application] menu.
Use node-inspector to provide the node debugging environment you're looking for. It's fantastic.
Check WebStorm. It is a great IDE, and also you can directly run your nodejs code, or connect to a debugging-enabled node process already running. In both cases, WebStorm provides what you are looking for: trace program execution line by line and on every line check the state of every variable.
Try nodeunit npm module for testing nodejs server side codes.
Even though question is very old, there is a awesome IDE from Microsoft "Visual Studio Code" which is developed in intention with Javascript (Typescript) which is capable of debugging Node JS projects
Checkout this link https://code.visualstudio.com/docs/nodejs/nodejs-debugging
node inspect built-in CLI step debugging
It took a while, but at some point Node finally added built-in debugging:
node inspect main.js
and this leaves you at the first line of the program.
Navigate with:
n step to next line
s step into function
c continue
o step out
h get help
In order to view variables or inject code, you need to first enter REPL mode with:
repl
and then you can run commands as in a node interactive session, e.g. to see the value of a variable just write the variable name:
myvar
It is awkward to have to type those four characters repl all the time, but I don't know any alternative.
You can also add a debugger statement to where you want to break in the program after a c:
const i = 1;
debugger;
i = 2;
Related question: How do I debug Node.js applications?
Tested in Node.js v10.15.1, Ubuntu 19.10.

doh robot unavailable after running previous instance

I grabbed the latest dojo code to play around with the DOH robot. I have installed two exact copies of the dojo/dijit/dojox/util package: one on the root level of my server and one under /js/.
localhost/dojo
/dijit
/dojox
/util
Then another copy under:
localhost/js/dojo
js/dijit
js/dojox
js/util
When I navigate to http://localhost/util/doh/tests/Robot.html
, the DOH robot initializes fine and everything runs (the mouse moves, tests pass, etc.)
When I try to do the same thing, only in the /js folder, (eg, http://localhost/js/util/doh/tests/Robot.html) I almost always get the error:
Error: doh.robot not available; skipping test.
Sometimes the robot will load up fine and pass all of the tests. Sometimes I will have the Java popup asking permission to use the robot (when this happens, I get the doh.robot unavailable error.)
Any idea what could be causing this, or some tips to keep this from happening?
I have tried the following things (and even tried all combinations of these steps):
clear firefox settings (ctl+shif+del, check all)
f5, ctl+f5
kill the java process
restart the browser
restart the server
restart the computer
tried all different browsers, same effect
recompiled/resigned the DOHRobot.jar
The thing that really irks me is that I have seen it work fine before, so I know that java and plugins are installed correctly.
I can always go back to the top level and run the robot just fine; the problem only happens when I am in the /js/ directory.
Any tips would be great! Thanks
EDIT I think it works now. The problem was that I was recompiling the robot but not signing the JAR correctly. (Check the .bat file when you compile and notice how it looks for the keystore in the directory above you; when I was making the keystore it saved to the default user directory.) Even though I wasn't changing any of the java code, the JAR was still signed incorrectly. Also if anyone does this, one step I forgot to include was to clear the Java cache! I'm not sure how much that matters.
Anyway I think this is solved; it looks like I wasn't exactly describing the problem correctly either.

Javascript Code Coverage tool for IE

I've got a rather hideous and large javascript file that I've inherited from a dev I loathe. There is a lot of dead code, and I find I've spent a lot of time refactoring functions that aren't even called.
Ideally, I just want something that can tie into the js engine and keep track of when and how many times functions are called.
In FF, I can get a list of the functions by walking the window object, and dynamically wrap them all in a method that would log the call to them, and then call the function as normal.
Unfortunately, in IE, I can't use this as I can't seem to find a way to get a list of all the functions that have been loaded. And I can't run this app in FF, as it's horribly browser specific. At last count there were 138 lines containing "new ActiveXObject(...)"
Help, either with a tool that can do this, or at the very least, a way to get a list of the functions that IE7 has loaded from the user script.
Thanks
-c
Try JSCoverage.
JSCoverage is a tool that measures
code coverage for JavaScript programs.
JSCoverage works by instrumenting the
JavaScript code used in web pages.
Code coverage statistics are collected
while the instrumented JavaScript code
is executed in a web browser.
The instrumentation can be done on-the-fly if you set the JSCoverage Server to run as an HTTP proxy and configure your browser to go through it.
One way to use it is:
Launch JSCoverage Server in proxy mode:
jscoverage-server --proxy --verbose
Configure your browser to you use localhost:8080 as the HTTP proxy.
Add the following bookmarklet, making sure the relative path to jscoverage is correct:
javascript:void(window.open('jscoverage/jscoverage.html'))
Run your tests.
Run the bookmarklet. It will popup a new window that shows you the coverage results.
There is a Firebug extension for JS Code Coverage...
FirebugCodeCoverage 0.1 (https://addons.mozilla.org/en-US/firefox/addon/4837)
Unfortunately, its not currently updated for the latest version of FF.

Categories

Resources