Simple way to pass config items from server to client
Last updated 7 years ago by henrikjoreteg .
Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install clientconfig 
SYNC missed versions from official npm registry.


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

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": "",
        "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


sample client usage:

var config = require('clientconfig');

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


npm i clientconfig

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


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



Current Tags

  • 1.1.1                                ...           latest (5 years ago)

7 Versions

  • 1.1.1                                ...           5 years ago
  • 1.1.0                                ...           5 years ago
  • 1.0.0                                ...           7 years ago
  • 0.0.4                                ...           8 years ago
  • 0.0.3                                ...           8 years ago
  • 0.0.2                                ...           8 years ago
  • 0.0.1                                ...           8 years ago
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 3
Dependencies (1)
Dev Dependencies (2)

Copyright 2014 - 2017 © |