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

nawdawg

v0.0.4

Published

Express middleware to add a delay to your responses to those you don't like.

Downloads

9

Readme

nawdawg

An Express middleware to show those you don't like how much you really don't like them by adding a delay to your server's responses based on conditions you provide.

Did your boss add busy work to your already slammed plate during the last 1-on-1? Are you Bruce Wayne and Clark Kent is accessing your app and you want to show him who's boss? Is your CEO taking too many golf trips? Oh your ex just signed up to use your company's app(s)? Lulz, we'll see about that.

Install

$ npm install nawdawg

Usage/Examples

import express from 'express'
import nawdawg from 'nawdawg'

const app = express()

// no arguments delays all requests by 100ms
app.use(nawdawg())

app.get('/', (req, res) => {
  res.send('At least 100ms has passed')
})
app.listen(8080)
import express from 'express'
import nawdawg from 'nawdawg'

const app = express()

// delay all requests by 1 second (1000 milliseconds)
app.use(nawdawg(1000))

app.get('/', (req, res) => {
  res.send('At least 1 second has passed')
})
app.listen(8080)
import express from 'express'
import nawdawg from 'nawdawg'

const app = express()

// delay all requests by user [email protected] (as defined in a session object on request) by 3 seconds
app.use(
  nawdawg({
    delay: 3000,
    delayer(req) {
      if (req.session.user === '[email protected]') {
        return true
      }
      return false
    },
  })
)

app.get('/', (req, res) => {
  res.send(`If you're [email protected], at least 3 seconds has passed`)
})
app.listen(8080)
import express from 'express'
import nawdawg from 'nawdawg'

const app = express()

// delay all requests by `userObject.delayByThisManyMilliseconds` number of milliseconds
// as defined by a column in the DB
app.use(
  nawdawg({
    async delayer(req) {
      const userObject = await findUser(req.session.user)
      const milliseconds = userObject && userObject.delayByThisManyMilliseconds
      return milliseconds || false
    },
  })
)

app.get('/', (req, res) => {
  res.send(
    `If you're logged in and have a delayByThisManyMilliseconds, at least that many milliseconds has passed`
  )
})
app.listen(8080)

API

nawdawg takes an optional options parameter that can be either a number that will delay all incoming requests by that number of milliseconds, or an object with the following parameters to control if and how to delay requests:

If options is not provided all requests will be delayed by 100ms.

  • options.delayer?: (req: express.Request): boolean | Promise<boolean> | number | Promise<number>
    • If delayer has async operations in it, make sure it returns a Promise (by either being itself an async function or explicitly returning a Promise if you still use callbacks).
    • If delayer returns a number, the request will be delayed by that many milliseconds
    • If delayer returns a boolean, the request will only be delayed if it's true and will be delayed by options.delay milliseconds
  • options.delay?: number = 100: the number of milliseconds to delay if options.delayer returns a boolean. If options.delayer returns a number, it will take precendent over options.delay.
import express from 'express'
import nawdawg from 'nawdawg'

const app = express()
app.use(nawdawg(options))