How to use where clause in Knex
Create refunds with Stripe
Load HTML with Cheerio
How to send POST request with Axios
Find intersection of array in Lodash
Powered by Official white Bloop logo with a period

Terms / Privacy / Search / Support

  • function getLastAccess(_score) {
      // parseResponse
      const score = _score * 1;
    
      // throw if token not found or expired
      if (_score == null || Date.now() > score + this.ttl) {
        throw new Errors.HttpStatusError(403, 'token has expired or was forged');
      }
    
      return score;
    }
    
    
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">function</span> <span class="token function">getLastAccess</span><span class="token punctuation">(</span><span class="token parameter">_score<span class="token operator">:</span> any</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">number</span></code><div class="typing-tooltip-markup">Parse last access</div></pre>
    /makeomatic/ms-users mit
    0
  • async function headAction({ params }) {
      
      //...
    if (exists === 0) {
        throw new HttpStatusError(404, "there aren't any files");
      }
    
      return response;
    }
    
    
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">function</span> <span class="token function">headAction</span><span class="token punctuation">(</span><span class="token parameter"><span class="token punctuation">{</span> params <span class="token punctuation">}</span><span class="token operator">:</span> <span class="token punctuation">{</span> params<span class="token operator">:</span> any<span class="token punctuation">;</span> <span class="token punctuation">}</span></span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">Promise</span><span class="token operator">&lt;</span><span class="token builtin">any</span><span class="token operator">></span> <span class="token keyword">module</span> headAction</code></pre>
    /makeomatic/ms-files MIT
    0
  • async function removeUser({ params }) {
      
      //...
    const [internal, meta] = await Promise
        .bind(context, username)
        .then(getInternalData)
        .then(addMetadata);
    
      const roles = (meta[audience].roles || []);
      if (intersection(roles, ADMINS).length > 0) {
        throw new Errors.HttpStatusError(400, 'can\'t remove admin user from the system');
      }
    
      const transaction = redis.pipeline();
      const alias = internal[USERS_ALIAS_FIELD];
      
      //...
    }
    
    
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">function</span> <span class="token function">removeUser</span><span class="token punctuation">(</span><span class="token parameter"><span class="token punctuation">{</span> params <span class="token punctuation">}</span><span class="token operator">:</span> <span class="token punctuation">{</span> params<span class="token operator">:</span> any<span class="token punctuation">;</span> <span class="token punctuation">}</span></span><span class="token punctuation">)</span><span class="token operator">:</span> globalThis<span class="token punctuation">.</span><span class="token builtin">Promise</span><span class="token operator">&lt;</span><span class="token builtin">any</span><span class="token operator">></span> <span class="token keyword">module</span> removeUser</code><div class="typing-tooltip-markup"><em>@api</em> — {amqp} <prefix>.remove Remove User<br><br><em>@apiVersion</em> — 1.0.0<br><br><em>@apiName</em> — RemoveUser<br><br><em>@apiGroup</em> — Users<br><br><em>@apiDescription</em> — Removes user from system. Be careful as this operation is not revertible.<br><br><em>@apiParam</em> — (Payload) {String} username - user's email or id</div></pre>
    /makeomatic/ms-users mit
    0
  • async function getFileCount({ params }) {
      
      //...
    const [username] = await Promise
        .bind(this, ['files:info:pre', owner])
        .spread(this.hook);
    
      if (!username) {
        throw new HttpStatusError(404, `User "${owner}" not found`);
      }
    
      const totalCount = this.redis.scard(FILES_USER_INDEX_KEY(username));
      const publicCount = this.redis.scard(FILES_USER_INDEX_PUBLIC_KEY(username));
    
      
    
      //...
    }
    
    
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">function</span> <span class="token function">getFileCount</span><span class="token punctuation">(</span><span class="token parameter"><span class="token punctuation">{</span> params <span class="token punctuation">}</span><span class="token operator">:</span> any</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">Promise</span><span class="token operator">&lt;</span><span class="token builtin">any</span><span class="token operator">></span> <span class="token keyword">module</span> getFileCount</code><div class="typing-tooltip-markup">Returns file count for specified user<br><br><em>@param</em> <code>opts.username</code><br><br><em>@return</em></div></pre>
    /makeomatic/ms-files MIT
    0
  • const http = require('http');
    
    // Server has a 5 seconds keep-alive timeout by default
    http
      .createServer((req, res) => {
        res.write('hello\n');
        res.end();
      })
      .listen(3000);
    
    setInterval(() => {
      // Adapting a keep-alive agent
      http.get('http://localhost:3000', { agent }, (res) => {
        res.on('data', (data) => {
          // Do nothing
        });
      });
    }, 5000); // Sending request on 5s interval so it's easy to hit idle timeout
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token punctuation">(</span>alias<span class="token punctuation">)</span> <span class="token keyword">module</span> <span class="token string">"http"</span> <span class="token keyword">import</span> http</code><div class="typing-tooltip-markup">To use the HTTP server and client one must <code>require('http')</code>.<br><br>The HTTP interfaces in Node.js are designed to support many features of the protocol which have been traditionally difficult to use. In particular, large, possibly chunk-encoded, messages. The interface is careful to never buffer entire requests or responses, so the user is able to stream data.<br><br>HTTP message headers are represented by an object like this:<br><br><pre class="code js"><code class="language-js">{ 'content-length': '123', 'content-type': 'text/plain', 'connection': 'keep-alive', 'host': 'mysite.com', 'accept': '*' }</code></pre><br><br>Keys are lowercased. Values are not modified.<br><br>In order to support the full spectrum of possible HTTP applications, the Node.js HTTP API is very low-level. It deals with stream handling and message parsing only. It parses a message into headers and body but it does not parse the actual headers or the body.<br><br>See <code>message.headers</code> for details on how duplicate headers are handled.<br><br>The raw headers as they were received are retained in the <code>rawHeaders</code>property, which is an array of <code>[key, value, key2, value2, ...]</code>. For example, the previous message header object might have a <code>rawHeaders</code>list like the following:<br><br><pre class="code js"><code class="language-js">[ 'ConTent-Length', '123456', 'content-LENGTH', '123', 'content-type', 'text/plain', 'CONNECTION', 'keep-alive', 'Host', 'mysite.com', 'accepT', '*' ]</code></pre><br><br><em>@see</em> — <a href="https://github.com/nodejs/node/blob/v16.9.0/lib/http.js">source</a></div></pre>
    Docs
    1
  • const http = require('http');
    const agent = new http.Agent({ keepAlive: true });
    
    function retriableRequest() {
      const req = http
        .get('http://localhost:3000', { agent }, (res) => {
          // ...
        })
        .on('error', (err) => {
          // Check if retry is needed
          if (req.reusedSocket && err.code === 'ECONNRESET') {
            retriableRequest();
          }
        });
    }
    
    retriableRequest();
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token punctuation">(</span>alias<span class="token punctuation">)</span> <span class="token keyword">module</span> <span class="token string">"http"</span> <span class="token keyword">import</span> http</code><div class="typing-tooltip-markup">To use the HTTP server and client one must <code>require('http')</code>.<br><br>The HTTP interfaces in Node.js are designed to support many features of the protocol which have been traditionally difficult to use. In particular, large, possibly chunk-encoded, messages. The interface is careful to never buffer entire requests or responses, so the user is able to stream data.<br><br>HTTP message headers are represented by an object like this:<br><br><pre class="code js"><code class="language-js">{ 'content-length': '123', 'content-type': 'text/plain', 'connection': 'keep-alive', 'host': 'mysite.com', 'accept': '*' }</code></pre><br><br>Keys are lowercased. Values are not modified.<br><br>In order to support the full spectrum of possible HTTP applications, the Node.js HTTP API is very low-level. It deals with stream handling and message parsing only. It parses a message into headers and body but it does not parse the actual headers or the body.<br><br>See <code>message.headers</code> for details on how duplicate headers are handled.<br><br>The raw headers as they were received are retained in the <code>rawHeaders</code>property, which is an array of <code>[key, value, key2, value2, ...]</code>. For example, the previous message header object might have a <code>rawHeaders</code>list like the following:<br><br><pre class="code js"><code class="language-js">[ 'ConTent-Length', '123456', 'content-LENGTH', '123', 'content-type', 'text/plain', 'CONNECTION', 'keep-alive', 'Host', 'mysite.com', 'accepT', '*' ]</code></pre><br><br><em>@see</em> — <a href="https://github.com/nodejs/node/blob/v16.9.0/lib/http.js">source</a></div></pre>
    Docs
    1
  • //...
    const assert = require('assert')
    const url = 'http://www.davidmarkclements.com/ncb3/some.json'
    
    http.get(url, (res) => {
      const size = parseInt(res.headers['content-length'], 10)
      const buffer = Buffer.allocUnsafe(size)
      var index = 0
      res.on('data', (chunk) => {
        chunk.copy(buffer, index)
        index += chunk.length
      })
      res.on('end', () => {
        assert.equal(size, buffer.length)
        console.log('GUID:', JSON.parse(buffer).guid)
      })
    })
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token punctuation">(</span>alias<span class="token punctuation">)</span> <span class="token keyword">function</span> <span class="token function">assert</span><span class="token punctuation">(</span><span class="token parameter">value<span class="token operator">:</span> unknown<span class="token punctuation">,</span> message<span class="token operator">?</span><span class="token operator">:</span> string <span class="token operator">|</span> Error</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token keyword">asserts</span> <span class="token function">value</span> <span class="token punctuation">(</span>alias<span class="token punctuation">)</span> <span class="token keyword">namespace</span> assert <span class="token keyword">import</span> assert</code><div class="typing-tooltip-markup">An alias of {@link ok }.<br><br><em>@since</em> — v0.5.9<br><br><em>@param</em> <code>value</code> — The input that is checked for being truthy.</div></pre>
    /PacktPublishing/Node-Cookbook mit
    0
  • module.exports.getQueryMetadata = function(request, next) {
      
      //...
    if (request.queryMetadata && request.queryMetadata.query) {
        
        //...
    } else if (name === "query-metadata") {
        
        //...
    } else {
          
          //...
    var req = http.get(url, (res) => {
              var result = "";
              res.setEncoding('utf8');
              res.on('data', (data) => {
                result += data;
              });
              res.on('end',function() {
                debug("raw metadata:" + result);
                request.queryMetadata = JSON.parse(result);
    
                next();
              });
          });
          
          //...
    }
      }
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">var</span> module<span class="token operator">:</span> <span class="token punctuation">{</span> exports<span class="token operator">:</span> <span class="token keyword">typeof</span> module<span class="token punctuation">.</span>exports<span class="token punctuation">;</span> <span class="token punctuation">}</span></code></pre>
    /ColinMaudry/sparql-router mit
    0
  • request.get = function (url) {
      return new Promise((resolve, reject) => {
        const req = http.get(url, (res) => {
          const body = [];
    
          res.on('data', (chunk) => body.push(chunk));
          res.on('end', () => resolve(body.join('')));
        });
    
        req.on('error', (err) => reject(err));
      });
    }
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">module</span> request <span class="token keyword">const</span> request<span class="token operator">:</span> <span class="token keyword">typeof</span> request</code></pre>
    /FTLam11/Audio-Station-Scrobbler mit
    0
  • const { createProxyMiddleware, responseInterceptor } = require('http-proxy-middleware');
    
    const proxy = createProxyMiddleware({
      /**
       * IMPORTANT: avoid res.end being called automatically
       **/
      selfHandleResponse: true, // res.end() will be called internally by responseInterceptor()
    
      /**
       * Intercept response and replace 'Hello' with 'Goodbye'
       **/
      onProxyRes: responseInterceptor(async (responseBuffer, proxyRes, req, res) => {
        const response = responseBuffer.toString('utf8'); // convert buffer to string
        return response.replace('Hello', 'Goodbye'); // manipulate response and return the result
      }),
    });
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token punctuation">(</span>alias<span class="token punctuation">)</span> <span class="token keyword">function</span> <span class="token function">createProxyMiddleware</span><span class="token punctuation">(</span><span class="token parameter">context<span class="token operator">:</span> Filter <span class="token operator">|</span> Options<span class="token punctuation">,</span> options<span class="token operator">?</span><span class="token operator">:</span> Options</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token keyword">import</span><span class="token punctuation">(</span><span class="token string">"./types"</span><span class="token punctuation">)</span><span class="token punctuation">.</span>RequestHandler <span class="token keyword">import</span> createProxyMiddleware</code></pre>
    Docs
    0
  • // create an HTTP GET request
    // create an HTTP GET request
    var request = forge.http.createRequest({method: 'GET', path: url.path});
     
    // send the request somewhere
    // send the request somewhere
    sendSomehow(request.toString());
     
    // receive response
    // receive response
    var buffer = forge.util.createBuffer();
    var response = forge.http.createResponse();
    var someAsyncDataHandler = function(bytes) {
      if(!response.bodyReceived) {
        buffer.putBytes(bytes);
        if(!response.headerReceived) {
          if(response.readHeader(buffer)) {
            console.log('HTTP response header: ' + response.toString());
          }
        }
        if(response.headerReceived && !response.bodyReceived) {
          if(response.readBody(buffer)) {
            console.log('HTTP response body: ' + response.body);
          }
        }
      }
    };
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">var</span> request<span class="token operator">:</span> <span class="token builtin">any</span></code></pre>
    Docs
    0
  • fs.readFile('foo.txt', function (err, buf) {
      if (err) {
        if (err.code === 'ENOENT') {
          var httpError = createError(404, err, { expose: false })
        } else {
          var httpError = createError(500, err)
        }
      }
    })
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token builtin">any</span></code></pre>
    Docs
    0
  • var createError = require('http-errors')
    var express = require('express')
    var app = express()
     
    app.use(function (req, res, next) {
      if (!req.user) return next(createError(401, 'Please login to view this page.'))
      next()
    })
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token punctuation">(</span>alias<span class="token punctuation">)</span> <span class="token keyword">namespace</span> <span class="token function">createError</span> <span class="token punctuation">(</span>alias<span class="token punctuation">)</span> <span class="token keyword">const</span> createError<span class="token operator">:</span> createHttpError<span class="token punctuation">.</span>CreateHttpError <span class="token operator">&amp;</span> <span class="token punctuation">{</span> <span class="token punctuation">[</span>code<span class="token operator">:</span> <span class="token builtin">string</span><span class="token punctuation">]</span><span class="token operator">:</span> createHttpError<span class="token punctuation">.</span>HttpErrorConstructor<span class="token punctuation">;</span> HttpError<span class="token operator">:</span> createHttpError<span class="token punctuation">.</span>HttpErrorConstructor<span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token operator">&amp;</span> Record<span class="token operator">&lt;</span><span class="token operator">...</span><span class="token operator">></span> <span class="token operator">&amp;</span> <span class="token punctuation">{</span> <span class="token operator">...</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token keyword">import</span> createError</code></pre>
    Docs
    0
  • var err = createError(404, 'This video does not exist!')
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">var</span> err<span class="token operator">:</span> <span class="token builtin">any</span></code></pre>
    Docs
    0
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples