Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debug Node, what is keeping it running?

Tags:

node.js

I have a script written for Node.Js that collects a load of data, processes it, saves and then finishes. Unfortunately something I've done that is preventing the script from finishing and node closing, instead it remains open.

I'll probably just work my way through the changes I've made and try to track it down, but... Is there an easy way to debug node and find out what code / event / callback / connection or whatever, that it's waiting for?

I've had a look at node-inspector but I couldn't figure out how to track down anything keeping it open. Any advice?

like image 587
Mister Dai Avatar asked Feb 11 '13 09:02

Mister Dai


People also ask

How do I stop node from running in the background?

To stop your NodeJS server from running, you can use the ctrl+C shortcut which sends the interrupt signal to the Terminal where you start the server.

What is node JS and why is it running?

Node. js is a single-threaded, open-source, cross-platform runtime environment for building fast and scalable server-side and networking applications. It runs on the V8 JavaScript runtime engine, and it uses event-driven, non-blocking I/O architecture, which makes it efficient and suitable for real-time applications.

How do you stop a running code in node JS?

Method 1: Using the Ctrl+C key This shortcut can be used to stop any running process by hitting this command on terminal.


2 Answers

You can run your node.js program using wtfnode or add require('wtfnode').init(); on the first line or your program. It will then print the list of all the things keeping node open when you press ctrl+c to kill the process.

like image 168
ForbesLindesay Avatar answered Nov 10 '22 23:11

ForbesLindesay


When I've had this happen it's most often something like mongodb, amqp etc. That is database connections, network connections. Make sure you close those once you're done processing.

I guess you could use lsof -p <PID> and see what that says. I can see both mongodb and amqp in there.

like image 26
gipset Avatar answered Nov 10 '22 21:11

gipset