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 🙏

© 2026 – Pkg Stats / Ryan Hefner

express-args-resolver

v0.0.2

Published

A resolver of arguments for express

Readme

Express Arguments Resolver

Build Status Coverage Status npm version Code Climate npm

Resolve function arguments to express objects based on the arguments names.

Installation

$ npm install --save express-args-resolver

Usage

Express app

var express = require('express'),
    bodyParser = require('body-parser'),
    argsResolver = require('express-args-resolver');


var expressApp = express();
expressApp.use(bodyParser.text());

// to simplify the use of argsResolver.proxy
var app = {
    use: function(path, func) {
        expressApp.use(path, argsResolver.proxy(func));
    }
};

// the endpoints definitions go Here ...

expressApp.listen(3000, function() {
    console.log('Up and Running!');
});

The proxy function will create a closure resolving the arguments by name.

Request.params

app.use('/param/:id', function(id, res) {
    res.send(id);
});

In that case the closure will work someway like this:

function inner(id, res) {
    res.send(id);
}

function out(req, res, next) {
    var id = req.params['id'] || req.query['id'];
    return inner(id, res);
}

So we can call this endpoint from curl to test it:

$ curl http://localhost:3000/param/1234
1234

It will look on the resolver table trying to find a resolver for that name. We have one for res that pass the Response object, if it can't find one a default will be created, will look for the argument name on the params and on the query in that order.

Request.query

app.use('/query', function(name, res) {
    res.send(name);
});

In that case we don't have 'name' on the params object, we can pass it as a query:

$ curl http://localhost:3000/query?name=test
test

Request.body

app.use('/body', function(body, res) {
    res.send(body);
});

Same here using bodyParser and resolving the body argument:

$ curl http://localhost:3000/body --data "dataSent" --header "Content-Type: text/plain"
dataSent

List of resolvers

  • req: Request
  • request: Request
  • res: Response
  • response: Response
  • next: next (callback)
  • params: Request.params
  • query: Request.query
  • body: Request.body

Add / change resolvers

You can add your own resolver. If you are using something like passport for auth, maybe you want to have a resolver for user and/or username.

// resolver for user
argsResolver.addResolver('user', function(req, res, next) {
    return req.user;
});

// resolver for username
argsResolver.addResolver('username', function(req, res, next) {
    if (req.user) {
        return req.user.username;
    }
});

Change the default resolver

The default resolver is used to resolve any param that is not in the table. If you don't change, it will look at the params for the name and if not found at the query.

Lets say you want to look at the body insted. You can do that:


// by default will look at body properties
argsResolver.changeDefault(function(name) {
    return function(req, res, next) {
        if (req.body && req.body[name]) {
            return req.body[name];
        }
    };
});

License

MIT