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

clientconfig

v1.1.1

Published

Simple way to pass config items from server to client

Downloads

321

Readme

clientconfig

Super simple mechanism for passing config items, such as API connection URLs, debug modes, etc from the server to client.

This is handy for apps built as single page apps where you're sending a pre-built js application to the client but still want to be able to pass it configuration information.

This is a very simple client side module for browserify. For more info on the approaches used here check out humanjavascript.com.

If you want to use it as a standalone, or with AMD etc. You can use clientconfig.bundle.js. It has no dependencies.

Since we're using cookies, here are some pertinent warnings as so aptly put by @lauriro here:

Unless sent over a secure channel (such as HTTPS), the information in cookies is transmitted in the clear text.

All sensitive information conveyed in these headers is exposed to an eavesdropper. A malicious intermediary could alter the headers as they travel in either direction, with unpredictable results. A malicious client could alter the Cookie header before transmission, with unpredictable results.

In short, don't send sensitive info this way unless you're on https.

How does it work?

Clientconfig simply looks for a cookie named config parses it as JSON and immediately wipes it out to avoid burdening subsequent requests with that extra overhead.

How do I use it?

On the server-side when serving up your request set a cookie containing the values you'd like to pass to the client in JSON.

If you're using node.js, express and getconfig it'd work like this:

sample config file:

{
    "client": {
        "apiConnectionUrl": "https://dev.api.com",
        "debugMode": true,
        "enviroment": "dev"
    },
    "otherServerConfigItems": {
        "dbpasswords": "etc"
    }
}

sample server:

var app = require('express')(),
    config = require('getconfig');

// our sample request handler
app.get('/app', function (req, res) {
    // here we set a cookie called "config" to a JSON encoded settings object
    res.cookie('config', JSON.stringify(config.client));
    // then render the html and respond
    res.render('app');
});

app.listen(80);

sample client usage:

var config = require('clientconfig');

console.log(config.apiConnectionUrl); // prints out connection url from server config JSON file

Installing

npm i clientconfig

Add it to your clientmodules or user browserify to include it in your app. voila!

Feedback

If you dig it, follow @HenrikJoreteg on the twitterwebs. If not, file issues or send pull requests :)

License

MIT