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?
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.
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.
Method 1: Using the Ctrl+C key This shortcut can be used to stop any running process by hitting this command on terminal.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With