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

jshare

v0.0.10

Published

Share you server side Node.js/Express variables with your client side Javascript.

Readme

NPM

JShare - Share your Node.js server side variables with your client side Javascript.

Installation:

You can install it directly from npm:

npm install jshare

Usage:

First, you need to add the JShare middleware to your Express app make sure to add it before the call to app.router:

app.js

var jshare = require('jshare');
app.configure(function(){
  app.use(jshare());
  app.use(app.router);
});

Next, you need to make a call out to the JShare helper method in your layout file:

layout.jade (or whatever other view engine you're using)

!!!
html
  head
    title= title
    link(rel='stylesheet', href='/stylesheets/style.css')
    != JShare()
  body!= body

Note

In previous versions of JShare, you had to call includeJShare() in your view, however this is now incompatible with EJS (thanks to minttoothpick for pointing this out). For backwards compatibility this will still work with Jade, however it is encouraged to use JShare() moving forward.

And finally, in your routes file, you can now attach any variables to the Response:

index.js

exports.index = function(req, res){
  res.jshare.person = {firstName : "Alex"};
  res.render('index', { title: 'Express' })
};

Now, in your client-side javascript, all of your variables that you set on the server side, will be available to you:

clientJS.js

alert(jshare.person.firstName);

Options:

Namespace

When calling the jshare() function from within your app.js, you can optionally pass in a namespace parameter. What that does is it prefaces the Javascript variables (both client and server side) with your custom namespace as opposed to 'JShare':

app.js

var jshare = require('jshare');
app.configure(function(){
  app.use(jshare('foo'));
  app.use(app.router);
});

index.js

exports.index = function(req, res){
  res.foo.person = {firstName : "Alex"}; //notice the res.foo instead of the res.jshare
  res.render('index', { title: 'Express' })
};

clientJS.js

alert(foo.person.firstName);

Script Tag

When calling the JShare() function from within the view, you can specify if you'd like to have the script tag automatically generated for you (this is the default) or not. You do this by specificying an options object:

layout.jade (or whatever other view engine you're using)

!!!
html
  head
    title= title
    link(rel='stylesheet', href='/stylesheets/style.css')
    != JShare({ outputScriptTag:true })
  body!= body

Dynamic External JS File

By default, the outputed JS gets put right where you call JShare in your view. If you'd rather have it be dumped in an external file, JShare provides the option to have a dynamic JS file be created, and the output of JShare() will be the path to that JS file:

layout.jade (or whatever other view engine you're using)

!!!
html
  head
    title= title
    link(rel='stylesheet', href='/stylesheets/style.css')
    != JShare({ useExternalJSFile:true })
  body!= body