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

one-config

v1.1.0

Published

One config file for your server and browser code.

Downloads

11

Readme

one-config

One config file for your server and browser code.

Installation

npm install one-config

Getting Started

Import and initialize one-config. Be sure to do this as early as possible in your server code.

require('one-config').initialize();

Create a one.config.js file in your project's root directory. You can optionally add a server property to store sensitive values. This property will not be available in the browser.

module.exports = {
  foo: 'bar'
  server: {
    topSecretDatabaseKey: 'EFAC34A4',
  },
};

Explicitly inject the initialization script into your HTML.

const { getScript } = require('one-config');

const html = `
  <html>
    <body>
      ...
      ${getScript()}
      <!-- Other bundles that depend on configuration -->
    </body>
  </html>
`;

That's it! You can now import and access configuration from anywhere in your application.

const config = require('one-config').config();

API

config()
  • Returns a copy of the raw config object. Can be used anywhere on server or client.
  • NOTE: Mutating this object will not affect the underlying config. Use extend or set to update the config.
extend(values: Object, dangerously: Boolean = false)
  • Values are merged with the original config object. Like the original config object, values can contain an optional server property.
  • NOTE: By default, this method will not apply updates in a browser environment or after forBrowser has been called. Use the dangerously argument to override this behavior. This method will not apply updates after freeze has been called.
forBrowser()
  • Returns the raw config object without the server property. Use this function when you can't inject an initialization script into HTML and need to provide the config value globally yourself using Webpack or a Babel.
forFile()
  • Returns a string representation of the oneConfig module to write to a file. Use this function when you can't inject an initialization script into HTML and need to provide the config globally yourself using Webpack or a Babel. Since this module is meant to be used in the browser, it only supports the config and get methods, and the server property will be excluded.
freeze()
  • Prevents any updates from being applied via extend or set.
get(key: String)
  • Gets the value at the specified key.
getScript()
  • Returns an initialization script tag to be injected into an HTML page.
initialize(source: (String|Object) = './one.config.js', handlers: Object = {})
  • Initializes the config for both server and browser environments. You can provide the optional source argument if you'd like to customize the file location or build an object at runtime. You can also provide the optional handlers argument if you'd like to perform logging, connect to a custom database, or use a feature like HttpContext. Handlers should be an object with get(key: String) and set(key: String, value: String) functions.
  • NOTE: This method should be called in your server's entry point as soon as possible.
set(key: String, value: <any>, dangerously: Boolean = false)
  • Sets a value at the specified key. See extend for an explanation of dangerously.

FAQ

Well, I searched NPM and couldn't find a library that met the following criteria:

  1. Works on both client and server
  2. Allows values to be defined at runtime, not just build time
  3. Allows sensitive values to be excluded from client-side code

Yes! Any values defined in the server field are excluded when you use the config returned by forBrowser, forFile, or getScript. Furthermore, server values will not get bundled into your client-side code if you import one-config, because config is required dynamically on the server.

Sure! You can simply call forFile and use Webpack or Babel to define the config globally yourself. Here's an example.

// webpack.config.js

const fs = require('fs');
const { forFile, initialize } = require('one-config');
const path = require('path');

// Initialize the config
initialize();

// Write the module to a file
fs.writeFileSync(
  path.resolve(__dirname, './one-config.js'),
  forFile()
)

module.exports = {
  // ... other webpack config
  resolve: {
    alias: {
      'one-config': path.resolve(__dirname, './one-config.js'),
    }
  }
}

Remember, you must import and configure one-config as early as possible in your server's entry file. Otherwise, you may be accessing one-config before it has been properly initialized.