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

next-plugin-node-config

v1.0.2

Published

Next.js and [node-config][], together at last.

Downloads

2,352

Readme

next-plugin-node-config

Next.js and node-config, together at last.

Install with npm:

npm install next-plugin-node-config

Install with Yarn:

yarn add next-plugin-node-config

Why?

Next.js already has built-in support for runtime configuration (in fact, this plugin is implemented using that) –  so why involve node-config as well?

node-config provides some features that are nicer for large applications:

  1. Merging of (potentially many) different configuration files (including multiple supported formats) depending on the environment. This is useful for managing different configurations in staging, production, etc.
  2. Nice error messages with config.get(). Instead of an unhelpful message about accessing a property of undefined, or silent bugs caused by using missing values, config.get() will throw an error with the full key path being requested.
  3. It works in places where next/config doesn’t – for example, server files that have not been built by Next.js. In these situations, next/config will supply an undefined configuration because it has not performed its setup phase that populates these values – but config will still work.

How?

When called, this plugin imports config and uses the result to define serverRuntimeConfig and publicRuntimeConfig in the Next.js config that it returns.

  • serverRuntimeConfig will come from config.serverRuntimeConfig, or a key of your choosing defined by nodeConfigServerKey. For example, a value of server will select config.server. If any existing serverRuntimeConfig value exists, it will be merged.
  • publicRuntimeConfig will come from config.publicRuntimeConfig, or a key of your choosing defined by nodeConfigPublicKey. For example, a value of public will select config.public. If any existing publicRuntimeConfig value exists, it will be merged.
  • A webpack alias is added for the config module that points to a browser shim provided by this plugin. It exports an object containing the configuration values retrieved from next/config, and compatible get() and has() methods.

Usage

Add some configuration files, for example config/default.js, then add this plugin to next.config.js.

Simplest usage with no existing Next.js config:

const withNodeConfig = require("next-plugin-node-config");

module.exports = withNodeConfig();

With existing Next.js config:

const withNodeConfig = require("next-plugin-node-config");

module.exports = withNodeConfig({
  // These will be merged on top of anything that comes from `config`!
  serverRuntimeConfig: {
    secret: "entropy9"
  },
  publicRuntimeConfig: {
    api: "/graphql"
  },
  webpack(config, options) {
    // ...
    return config;
  }
});

Using the nodeConfigServerKey and nodeConfigPublicKey options, serverRuntimeConfig and publicRuntimeConfig can be named something nicer in your config files:

const withNodeConfig = require("next-plugin-node-config");

module.exports = withNodeConfig({
  nodeConfigServerKey: "server",
  nodeConfigPublicKey: "public"
});