Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<ol> <li><p>When passing an <code>Object</code> as the 1st argument, the URL should be broken up into individual pieces:</p> <pre><code>var options = { method: 'GET', protocol: 'https:', hostname: 'www.mywebsite.com', path: '/' + scanitem }; var _request = https.get(options, ...); </code></pre> <p>The <code>options</code> that are used are covered under <a href="http://nodejs.org/api/https.html#https_https_request_options_callback" rel="nofollow"><code>https.request()</code></a>, which <code>https.get()</code> is a convenience variant of.</p> <p>You can also pass the URL <code>String</code>, which <code>https.get()</code> will be run through <a href="http://nodejs.org/api/url.html#url_url_parse_urlstr_parsequerystring_slashesdenotehost" rel="nofollow"><code>url.parse()</code></a> for you:</p> <pre><code>var _request = https.get(url, ...); </code></pre></li> <li><p>JavaScript doesn't have block-scoped variables (<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let" rel="nofollow">yet</a>). So, despite the location of <code>var body = "";</code>, every iteration of your <code>while</code> loop is still appending to the same <code>body</code>.</p> <p>This isn't as much a concern when the variable is only used by synchronous tasks, like <code>scanitem</code>, <code>url</code>, and <code>options</code> are. But, when mixing in asynchronous tasks like <code>https.get()</code>, you won't likely get the result you're expecting.</p> <p>In the current absence of block-scoped variables, you can use a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Closures#Creating_closures_in_loops.3A_A_common_mistake" rel="nofollow">closure</a> to create an additional <code>function</code> scope.</p> <p>As <code>List</code> appears to be an <code>Array</code>, you can use an iterator <code>function</code> with <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach" rel="nofollow"><code>.forEach()</code></a> for this:</p> <pre><code>List.forEach(function (scanitem) { var body = ''; var url = 'https://www.mywebsite.com/'+scanitem; https.get(url, function (res) { // etc. }); }); </code></pre> <p>And, for the <code>Limit</code>, you can use <code>.splice()</code> to remove and work with the portion of the <code>Array</code> you want:</p> <pre><code>List.splice(0, Limit).forEach(function (scanitem) { // etc. }); </code></pre></li> </ol> <hr> <p>Also, unlike with <code>https.request()</code>, you're not required to call <code>_request.end()</code> when using <code>https.get()</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload