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

  • var accepts = require("accepts");
    var http = require("http");
    function app(req, res) {
      var accept = accepts(req); // the order of this list is significant; should be server preferred order
      switch (accept.type(["json", "html"])) {
        case "json":
          res.setHeader("Content-Type", "application/json");
          res.write('{"hello":"world!"}');
          break;
        case "html":
          res.setHeader("Content-Type", "text/html");
          res.write("hello, world!");
          break;
        default:
          // the fallback is text/plain, so no need to specify it above
          res.setHeader("Content-Type", "text/plain");
          res.write("hello, world!");
          break;
      }
      res.end();
    }
    http.createServer(app).listen(3000);
    
    Docs
    0
  • var accepts = require("accepts");
    var http = require("http");
    function app(req, res) {
      var accept = accepts(req); // the order of this list is significant; should be server preferred order
      switch (accept.type(["json", "html"])) {
        case "json":
          res.setHeader("Content-Type", "application/json");
          res.write('{"hello":"world!"}');
          break;
        case "html":
          res.setHeader("Content-Type", "text/html");
          res.write("hello, world!");
          break;
        default:
          // the fallback is text/plain, so no need to specify it above
          res.setHeader("Content-Type", "text/plain");
          res.write("hello, world!");
          break;
      }
      res.end();
    }
    http.createServer(app).listen(3000);
    
    Docs
    0
  • // index.js
    
    const languageEncoding = require("detect-file-encoding-and-language");
    
    const pathToFile =
      "/home/username/documents/my-text-file.txt";
    
    languageEncoding(pathToFile).then((fileInfo) =>
      console.log(fileInfo)
    );
    // Possible result: { language: japanese, encoding: Shift-JIS, confidence: { encoding: 0.94, language: 0.94 } }
    
    Docs
    0
  • // app.js
    
    const languageEncoding = require("detect-file-encoding-and-language");
    
    document
      .getElementById("my-input-field")
      .addEventListener("change", inputHandler);
    
    function inputHandler(e) {
      const file = e.target.files[0];
    
      languageEncoding(file).then((fileInfo) =>
        console.log(fileInfo)
      );
      // Possible result: { language: french, encoding: CP1252, confidence: { encoding: 1, language: 0.97 } }
    }
    
    Docs
    0
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples