Chrome "Take Heap Snapshot" never completes - node.js

Summary:
I'm trying use Chrome's "Take Heap Snapshot" to track down a memory leak in some node.js code, but the act of taking a snapshot never completes.
Am I mis-using the tool somehow?
Details:
Here's the node.js app:
#!/usr/bin/env node
var serialserver = require('./p5.serialserver');
serialserver.start();
console.log("p5.serialserver is running");
Here's how I invoke it, and what it prints out:
$ node --inspect ./p5serial
Debugger listening on port 9229.
Warning: This is an experimental feature and could change at any time.
To start debugging, open the following URL in Chrome:
chrome-devtools://devtools/remote/serve_file/#521e5b7e2b7cc66b4006a8a54cb9c4e57494a5ef/inspector.html?experiments=true&v8only=true&ws=localhost:9229/node
p5.serialserver is running
In Chrome (Version 59.0.3071.115), running under OSX 10.12.6 (Sierra), I open the given URL and click on Take Heap Snapshot. I see the icon in the left column which says:
Snapshot 1
Snapshotting...
... but even after waiting for ten minutes, the snapshot hasn't completed. This is not a particularly large node application.
What am I missing?

I was able to successfully take a heap snapshot of the following:
const http = require('http');
const port = 3000;
const requestHandler = (request, response) => {
console.log(request.url);
response.end(`you requested ${request.url}`);
};
const server = http.createServer(requestHandler);
server.listen(port, (err) => {
if (err) {
return console.log('something bad happened', err);
}
console.log(`server is listening on ${port}`);
});
Invoked via node --inspect server.js
Version info:
macOS Sierra 10.12.6
Chrome 62.0.3174.0 (Official Build) canary (64-bit)
Try downloading Chrome Canary and see if the problem is resolved in the latest version of Chrome.
If not, then there may be something going on with this serial server. Did you build it, or is it a library?

Related

Nodemon server won't start

I was trying to create a simple room based webchat app using socket.io. But I've been facing issues with serving the node server file with node and nodemon. I've tried different ports i.e., 8000, 8080, 80 and I've also tried reinstalling node and nodemon both locally and globally but nothing seems to work. I guess the code is alright because I was following a tutorial (that didn't include any link to the source code though). I'm on windows so I've also used used the command
Set-ExecutionPolicy Unrestricted
Here are the screenshots of Windows power shell and command prompt
PS: I am a newbie, so please consider that I might have missed something basic.
const io = require('socket.io')(8000)
const users = {};
io.on('connection', socket =>{
socket.on('new-user-joined',name =>{
users[socket.id] = name;
socket.broadcast.emit('user-joined', name);
});
socket.on('send', message =>{
socket.broadcast.emit('receive', {message: message,name: user[socket.id]});
});
})

Unable to run node API on Ubuntu (AWS)

I have deployed node API on Ubuntu server (AWS) but when I run my app it throw below error given in screen shot. due to I am not able to make API requst.
I have trid to kill port and execute it again but it gives e same error
my node app is running on 8081 on local machine
var connection = mongoose
.connect(url, option)
.then(result => {
app.listen(PORT);
console.log("Running RestHub on port " + PORT)
})
.catch(err => {
console.log(err);
});
after uploading code in Ubuntu sever it does not work
I am struggling to fix this issue since yesterday but could not fix yet.
Please your help would be highly appreciated
Thanks you

why does my nodejs program run differently with --inspect-brk option

I've got a simple nodejs program that tries to connect to NetworkManager via DBus using dbus-network-manager. Unfortunately, I can't use chrome://inspect to debug it because it behaves differently in the debugger.
Here's the code:
const NetWorkManager = require('dbus-network-manager').connect()
.then(nm => {
// this branch taken when run with or without --inspect option
console.log ('connected successfully');
})
.catch(err => {
// this branch taken when node launched with --inspect-brk option
console.log ('failed to connect, error was: ' + err);
})
And here's how it runs in 3 different scenarios:
$ node app.js
DBus test app running in development mode connected successfully
node --inspect app.js
Debugger listening on ws://127.0.0.1:9229/3fcf6bd4-f6fa-4bf2-8dcd-30c8fdcd14b8
For help see https://nodejs.org/en/docs/inspector
DBus test app running in development mode
connected successfully
node --inspect-brk app.js
Debugger listening on ws://127.0.0.1:9229/e935e8b4-0d78-4ad0-a5c1-894e5631c8fa
For help see https://nodejs.org/en/docs/inspector
Debugger attached.
DBus test app running in development mode
failed to connect, error was: Error: No introspectable
I can work around the problem given that it seems to run ok with --inspect, but I'd love to know why this is happening at all.
Thanks!

Do not know how to start debugging a Node.js code in JetBrains WebStorm

I am trying to learn to debug a Node.js code in WebStorm. The code is the simple "Getting Started" code from here:
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World\n');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
The above code works correctly after I ran node app.js at command line and visited http://localhost:3000. Next I tried to debug it locally in JetBrains WebStorm following instructions here. This is the debug configuration of Node.js application in WebStorm:
I clicked the bug icon to run the Node.js code under debugging mode. This is the output:
"C:\Program Files (x86)\JetBrains\WebStorm 10.0.3\bin\runnerw.exe" "C:\Program Files\nodejs\node.exe" --debug-brk=24163 --nolazy --inspect app.js
Debugger listening on ws://127.0.0.1:24163/bffa51bd-74bd-4257-8174-2c8ab3768e17
For help see https://nodejs.org/en/docs/inspector
I guess that it is equivalent to running the "node app.js" command. The instruction says I need to "Perform the steps that will trigger the execution of the code with the breakpoints." I guess that means I open the URL "http://localhost:3000" in browser to send a request to the web server that the app.js is implementing, and I did it. I have set up breakpoints on every line of the source app.js and I expected that the breakpoints should be hit somewhere in the source, but the browser reported an "Unable to connect" error and nothing happened in WebStorm -- no breakpoint is hit. I have checked the instructions but could not figure out what I am missing. Could you please help me with this problem? If you need more information please let me know. Thanks a lot!
PS: app.js is in the ...\test folder.
==Edit:==
PS2: The browser can print "Hello world" just because "node app.js" is still running. After I terminated it, the browser reports "Unable to connect". So that means the URL does not know how to connect to the webserver launched by WebStorm debugger. Is the port wrong?
PS3: This is what returns from http://localhost:31496/json/list (the port number changes in every debugging session). Hope it can help troubleshooting.
description "node.js instance"
devtoolsFrontendUrl "chrome-devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=127.0.0.1:31496/0f03cac0-648f-4c13-9cb9-39bb5e3a81a6"
faviconUrl "https://nodejs.org/static/favicon.ico"
id "0f03cac0-648f-4c13-9cb9-39bb5e3a81a6"
title "app.js"
type "node"
url "file://E:..._test_app.js"
webSocketDebuggerUrl "ws://127.0.0.1:31496/0f03cac0-648f-4c13-9cb9-39bb5e3a81a6"
As far as I can see, you are using webStorm 10. It's quite old and doesn't support new debugger protocol introduced in recent Node.js updates.
Please downgrade Node.js to v. 4.x (at least) or, better, upgrade Webstorm to 2017.3

http server listening in old port

First i installed the node js with webmatrix and ran a sample node js app. the app was assigned a random port. http://localhost:62369/. After that i installed the express module. As said in their doc. i wrote,
var app = express();
app.get('/',function (req, res) {
res.send('hello world!!');
})
app.listen(3000);
Then i restarted the server. The launched browser was still pointing to http://localhost:62369/ instead of port 3000. Moreover http://localhost:3000/ was not working.
I suggest you to run this code so you can see if you have any problem on saving the code with your IDE:
var app = express(),
port = 4555;
app.get('/',function (req, res) {
res.send('hello world!!');
})
console.log("Server is running on " + port);
app.listen(port);
After that, you need to change the port variable only. It's helpful if you comment what you see after running this code on the console.
make sure that you've saved your code in your file (open it with another editor, maybe something's wrong with your editor), close the command line window and open it again. try to run server. I'm sure the problem is not because of node or express. Try to check everything again.
And also run your server with command line:
cd path/folder
node myFile
I don't know what are you using to run server, but if it's something with UI (in comments you mentioned a click) it can cache your code or something like that. So it's safer to run with commend line.

Resources