day-6.mjs
December 30, 2021 ยท View on GitHub
/////////////////////////////////////////////////////////////////////////////// // Day 6 - Is anybody listening? // // #region problem // /////////////////////////////////////////////////////////////////////////////// // Detect if DevTools can connect to the current Node.js instance and return // // a different result if connected or not. // ///////////////////////////////////////////////////////////////////////////////
/**
- @returns {boolean} */ function isListeningForDevToolsConnections() { // ... }
/////////////////////////////////////////////////////////////////////////////// // #endregion problem // ///////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////// // Test - Leave code after this alone // // #region test // ///////////////////////////////////////////////////////////////////////////////
import inspector from 'node:inspector'; import assert from 'node:assert/strict';
assert.strictEqual(isListeningForDevToolsConnections(), false); inspector.open(0, '127.0.0.1', false); assert.strictEqual(isListeningForDevToolsConnections(), true); inspector.close(); assert.strictEqual(isListeningForDevToolsConnections(), false);
/////////////////////////////////////////////////////////////////////////////// // #endregion test // ///////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////// // Hints - Encoded in ROT13 encoded // // #region hints // /////////////////////////////////////////////////////////////////////////////// // // // Fvzcyr: hfr gur abqr:vafcrpgbe zbqhyr. // // // /////////////////////////////////////////////////////////////////////////////// // #endregion hints // ///////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////// // Use Cases // // #region uses // /////////////////////////////////////////////////////////////////////////////// // // // Sometimes you only want to do compute heavy workflows if someone is going // // to listen, so debug level tracking etc. is available, or saving variables // // and keeping debug data around that would normally be cleaned up. // // // /////////////////////////////////////////////////////////////////////////////// // #endregion uses // ///////////////////////////////////////////////////////////////////////////////