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

dpd-event

v1.1.2

Published

Deployd module to create custom events at a specified URL.

Downloads

12

Readme

Event Resource

This custom resource type allows you to write an event that will run when the resource's route receives a GET or POST request.

Installation

In your app's root directory, type npm install dpd-event into the command line or download the source. This should create a dpd-event directory in your app's node_modules directory.

See Installing Modules for details.

Usage

The On POST event will be executed when the resource's route (or a subroute) receives a POST request, and likewise with the On GET event.

It is strongly recommended that you reserve the On GET event for operations that return a value, but don't have any side effects of modifying the database or performing some other operation.

If your resource is called /add-follower, you can trigger its POST event from dpd.js:

dpd.addfollower.post('320d6151a9aad8ce', {userId: '6d75e75d9bd9b8a6'}, function(result, error) {
    // Do something
})

And over HTTP:

POST /add-follower/320d6151a9aad8ce
Content-Type: application/json
{
    "userId": "6d75e75d9bd9b8a6"
}

Event API

In addition to the generic custom resource event API, the following functions and variables are available while scripting the Event resource:

setResult(result)

Sets the response body. The result argument can be a string or an object.

// On GET /top-score
dpd.scores.get({$limit: 1, $sort: {score: -1}}, (result) => {
    setResult(result[0]);
});

getHeader(header)

Gets a request header. header is case insensitive.

if (getHeader('x-api-key') != 'mysecretapikey') cancel(401, 'bad api key');

setHeader(header, value)

Set a response header.

setHeader('Content-Type', 'text/javascript');
setResult('typeof myCallback === "function" && myCallback("hello world")');

setStatusCode(statusCode)

Sets the response http status code.

// temporary redirect to somewhere else
setStatusCode(302);
setHeader('Location', 'https://somesite/someotherplace');

url

The URL of the request, without the resource's base URL. If the resource is called /add-follower and receives a request at /add-follower/320d6151a9aad8ce, the url value will be /320d6151a9aad8ce.

// On GET /statistics
// Get the top score
if (url === '/top-score') {
    dpd.scores.get({$limit: 1, $sort: {score: -1}}, function(result) {
    setResult(result[0]);
    });
}

parts

An array of the parts of the url, separated by /. If the resource is called /add-follower and receives a request at /add-follower/320d6151a9aad8ce/6d75e75d9bd9b8a6, the parts value will be ['320d6151a9aad8ce', '6d75e75d9bd9b8a6'].

// On POST /add-score
// Give the specified user (/add-score/:userId) 5 points
var userId = parts[0];
if (!userId) cancel("You must provide a user");

dpd.users.put({id: userId}, {score: {$inc: 5}}, function(result, err) {
    if (err) cancel(err);
});

query

The query string object.

// On GET /sum
// Return the sum of the a and b properties (/sum?a=5&b=1)

setResult(Number(query.a) + Number(query.b));

body

The body of the request.

// On POST /sum
// Return the sum of the a and b properties {a: 5, b: 1}

setResult(Number(body.a) + Number(body.b));