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 🙏

© 2025 – Pkg Stats / Ryan Hefner

express-expose

v0.3.4

Published

Expose helpers and local variables to the client-side

Readme

express-expose

NPM Version NPM Downloads Build Status Test Coverage

Expose helpers and local variables to the client-side.

Install

npm install -S express-expose

Usage

[email protected]:

var express = require('express');
var expose = require('express-expose');
app = expose(app);
app.expose(...);

[email protected] and [email protected]:

var express = require('express');
var expose = require('express-expose');
app.expose(...);

Versions

Examples

Exposing Objects

A common use-case for exposing objects to the client-side would be exposing some properties, perhaps the express configuration. The call to app.expose(obj) below defaults to exposing the properties to app.*, so for example app.views, app.title, etc.

app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.set('title', 'Example');
app.set('default language', 'en');

app.expose(app.settings);

Another use-case would be exposing helper methods, perhaps the same ones as you are currently exposing to templates. Below we expose the math object as utilities to our templates, as well as the client-side. Within a template we would call add(1,2), and on the CS we would call utils.add(1,2), since we have passed the namespace "utils".

var math = { add: function(a,b){ return a + b; } };
app.expose(math, 'utils').helpers(math);

Sometimes you might want to output to a different area, so for this we can pass an additional param "languages" which tells express which buffer to write to, which ends up providing us with the local variable "languages" in our template, where the default is "javascript". The "app" string here is the namespace.

app.expose({ en: 'English', fr: 'French' }, 'app', 'languages');

You'll then want to output the default buffer (or others) to your template, in Jade this would look something like:

script!= javascript

And in EJS:

<script><%- javascript %></script>

Raw JavaScript

It is also possible to expose "raw" javascript strings.

app.expose('var some = "variable";');

Optionally passing the destination buffer, providing us with the "head" local variable, instead of the default of "javascript".

app.expose('var some = "variable";', 'head');

Exposing Functions

Exposing a named function is easy too, simply pass it in with an optional buffer name for placement within a template much like above.

app.expose(function someFunction(){
  return 'yay';
}, 'foot');

Self-Calling Functions

Another alternative is passing an anonymous function, which executes itself, creating a "wrapper" function.

app.expose(function(){
  function notify() {
    alert('this will execute right away :D');
  }
  notify();
});

Request-Level Exposure

Finally we can apply all of the above at the request-level as well, below we expose "app.current.user" as { name: 'tj' }, for the specific request only.

app.get('/', function(req, res){
  var user = { name: 'tj' };
  res.expose(user, 'app.current.user');
  res.render('index', { layout: false });
});

License

MIT