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
    // 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('<b>hello, world!</b>')
          break
        default:
          // the fallback is text/plain, so no need to specify it above
    // 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
  • function build (req) {
      
      //...
    req.accepts = function reqAccepts (...args) {
        const accept = accepts(this)
        return accept.types.apply(accept, args)
      }
    
      req.acceptsEncodings = function (...args) {
        const accept = accepts(this)
        return accept.encodings.apply(accept, args)
      }
    
      
    
      //...
    }
    
    /fyrejet/fyrejet MIT
  • const search = async (req, res, next) => {
    	
    	//...
    if (!(await fs.isDir(req.absolute))) return next()
    	if (accepts(req).type('html') !== 'html') return next() // todo: support JSON & plain text
    
    	let results = []
    	
    	//...
    }
    
    
    /derhuerst/casket ISC
  • const frontend = async (req, res, next) => {
    	if (!(await fs.isDir(req.absolute))) return next()
    	if (accepts(req).type('html') !== 'html') return next()
    
    	let files = (await fs.readDir(req.absolute))
    	.map((name) => ({
    		name, path: '/' + path.join(req.relative, name)
    	}))
    
    	
    
    	//...
    }
    
    
    /derhuerst/casket ISC
  • const librarySchema = new Schema({
      name: String,
      books: {
        type: Map,
        of: new Schema({
          title: String,
          author: {
            type: 'ObjectId',
            ref: 'Person'
          }
        })
      }
    });
    const Library = mongoose.model('Library, librarySchema');
    
    Docs
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples