版博士V2.0程序
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # why-is-node-running
  2. Node is running but you don't know why? `why-is-node-running` is here to help you.
  3. ## Installation
  4. Node 8 and above:
  5. ```bash
  6. npm i why-is-node-running -g
  7. ```
  8. Earlier Node versions (no longer supported):
  9. ```bash
  10. npm i why-is-node-running@v1.x -g
  11. ```
  12. ## Usage
  13. ```js
  14. const log = require('why-is-node-running') // should be your first require
  15. const net = require('net')
  16. function createServer () {
  17. const server = net.createServer()
  18. setInterval(function () {}, 1000)
  19. server.listen(0)
  20. }
  21. createServer()
  22. createServer()
  23. setTimeout(function () {
  24. log() // logs out active handles that are keeping node running
  25. }, 100)
  26. ```
  27. Save the file as `example.js`, then execute:
  28. ```bash
  29. node ./example.js
  30. ```
  31. Here's the output:
  32. ```
  33. There are 5 handle(s) keeping the process running
  34. # Timeout
  35. /home/maf/dev/node_modules/why-is-node-running/example.js:6 - setInterval(function () {}, 1000)
  36. /home/maf/dev/node_modules/why-is-node-running/example.js:10 - createServer()
  37. # TCPSERVERWRAP
  38. /home/maf/dev/node_modules/why-is-node-running/example.js:7 - server.listen(0)
  39. /home/maf/dev/node_modules/why-is-node-running/example.js:10 - createServer()
  40. # Timeout
  41. /home/maf/dev/node_modules/why-is-node-running/example.js:6 - setInterval(function () {}, 1000)
  42. /home/maf/dev/node_modules/why-is-node-running/example.js:11 - createServer()
  43. # TCPSERVERWRAP
  44. /home/maf/dev/node_modules/why-is-node-running/example.js:7 - server.listen(0)
  45. /home/maf/dev/node_modules/why-is-node-running/example.js:11 - createServer()
  46. # Timeout
  47. /home/maf/dev/node_modules/why-is-node-running/example.js:13 - setTimeout(function () {
  48. ```
  49. **Important Note!**
  50. `unref`ed timers do not prevent the Node process from exiting. If you are running with Node v11.0.0 and above, `unref`ed timers will not be listed in the above list. Unfortunately, this is not supported in node versions below v11.0.0.
  51. ## CLI
  52. You can also run `why-is-node-running` as a standalone if you don't want to include it inside your code. Sending `SIGUSR1`/`SIGINFO` signal to the process will produce the log. (`Ctrl + T` on macOS and BSD systems)
  53. ```bash
  54. why-is-node-running /path/to/some/file.js
  55. ```
  56. ```
  57. probing module /path/to/some/file.js
  58. kill -SIGUSR1 31115 for logging
  59. ```
  60. To trigger the log:
  61. ```
  62. kill -SIGUSR1 31115
  63. ```
  64. ## Require CLI Option
  65. You can also use the node `-r` option to include `why-is-node-running`:
  66. ```bash
  67. node -r why-is-node-running/include /path/to/some/file.js
  68. ```
  69. The steps are otherwise the same as the above CLI section
  70. ## License
  71. MIT