npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

express-toss

v2.0.0

Published

Makes express router handlers aware of promises. Brings more clear dataflow to handlers.

Downloads

4

Readme

express-toss

Travis Coveralls ISC licensed npm|express-toss flowtype

Makes express router handlers aware of promises. Brings more clear dataflow to express handlers.

toss.method

Transforms (rq) => Promise function to (rq, rs) => void function for use inside Express' handlers.

resolving

import tosser from 'express-toss'

var toss = tosser({ debug: true })

express.get('/resource', toss.method(rq =>
{
  return db.query().then(transform) /* … */
}))

— return value is used as response body with status 200 and adequate mime. MIME would be determined automatically by express (application/json in case of Object, text/html in case of string, learn more).

rejecting

import tosser from 'express-toss'

var toss = tosser({ debug: true })

express.get('/resource', toss.method(rq =>
{
  throw new TypeError
}))

— sync throws or promise rejections will convert into 500s with specific JSON body. If debug = true body is detailed, if debug = false it is like a simple internal-ish error.

Resp()

import tosser from 'express-toss'
import Resp   from 'express-toss/Resp'

var toss = tosser({ debug: true })

express.get('/resource', toss.method(rq =>
{
  // use `Resp` to fine-control response
  return Resp(200, 'text/html', html)

  // can be used for 400s
  return Resp(400, { server: error })
}))

Resp([status], [mime], body) is applied to express' response. Resp can be sync-returned or used inside promise.

Wrong()

import tosser from 'express-toss'
import Wrong  from 'express-toss/Wrong'

var toss = tosser({ debug: true })

// use Wrong to create protocol-level errors
// Wrong(code) creates constructor for `code` error
var NotPermitted = Wrong('permission_required')
var NotFound = Wrong('user_not_found', { status: 404 })

express.get('/resource', toss.method(rq =>
{
  // throwing or returning `Wrong` to fine-control response
  throw NotPermitted()

  // details can be supplied
  throw NotFound({ username: 'username' })
}))

Wrong(code, [options]) creates new specific error factory. Calling that factory creates error instance. This instance can be throwed/rejected or sync-returned to indicate error situation.

flow

FlowType definitions included.

license

ISC © Strider, 2017 — 2019.