{"id":16292473,"url":"https://github.com/exogen/next-plugin-node-config","last_synced_at":"2025-03-20T03:30:51.905Z","repository":{"id":65424462,"uuid":"147055437","full_name":"exogen/next-plugin-node-config","owner":"exogen","description":"Combine node-config with Next.js' built-in support for runtime configuration","archived":false,"fork":false,"pushed_at":"2018-09-02T10:15:19.000Z","size":52,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-16T14:53:56.717Z","etag":null,"topics":["nextjs","nextjs-plugin","node-config"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/exogen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-02T04:52:31.000Z","updated_at":"2021-12-08T12:42:27.000Z","dependencies_parsed_at":"2023-01-23T01:45:25.984Z","dependency_job_id":null,"html_url":"https://github.com/exogen/next-plugin-node-config","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exogen%2Fnext-plugin-node-config","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exogen%2Fnext-plugin-node-config/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exogen%2Fnext-plugin-node-config/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exogen%2Fnext-plugin-node-config/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/exogen","download_url":"https://codeload.github.com/exogen/next-plugin-node-config/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244543734,"owners_count":20469552,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nextjs","nextjs-plugin","node-config"],"created_at":"2024-10-10T20:06:54.508Z","updated_at":"2025-03-20T03:30:51.544Z","avatar_url":"https://github.com/exogen.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# next-plugin-node-config\n\nNext.js and [node-config][], together at last.\n\nInstall with npm:\n\n```sh\nnpm install next-plugin-node-config\n```\n\nInstall with Yarn:\n\n```sh\nyarn add next-plugin-node-config\n```\n\n## Why?\n\nNext.js already has [built-in support for runtime configuration][next-config]\n(in fact, this plugin is implemented using that) –  so why involve node-config\nas well?\n\nnode-config provides some features that are nicer for large applications:\n\n1.  Merging of (potentially many) different [configuration files][files]\n    (including multiple supported formats) depending on the environment. This is\n    useful for managing different configurations in staging, production, etc.\n2.  Nice error messages with [`config.get()`][get]. Instead of an unhelpful\n    message about accessing a property of `undefined`, or silent bugs caused by\n    using missing values, `config.get()` will throw an error with the full key\n    path being requested.\n3.  It works in places where `next/config` doesn’t – for example, server files\n    that have not been built by Next.js. In these situations, `next/config` will\n    supply an undefined configuration because it has not performed its setup\n    phase that populates these values – but `config` will still work.\n\n## How?\n\nWhen called, this plugin imports `config` and uses the result to define\n`serverRuntimeConfig` and `publicRuntimeConfig` in the Next.js config that it\nreturns.\n\n- `serverRuntimeConfig` will come from `config.serverRuntimeConfig`, or a key of\n  your choosing defined by `nodeConfigServerKey`. For example, a value of\n  `server` will select `config.server`. If any existing `serverRuntimeConfig`\n  value exists, it will be merged.\n- `publicRuntimeConfig` will come from `config.publicRuntimeConfig`, or a key of\n  your choosing defined by `nodeConfigPublicKey`. For example, a value of\n  `public` will select `config.public`. If any existing `publicRuntimeConfig`\n  value exists, it will be merged.\n- A webpack alias is added for the `config` module that points to a browser shim\n  provided by this plugin. It exports an object containing the configuration\n  values retrieved from `next/config`, and compatible `get()` and `has()`\n  methods.\n\n## Usage\n\nAdd some configuration files, for example `config/default.js`, then add this\nplugin to `next.config.js`.\n\nSimplest usage with no existing Next.js config:\n\n```js\nconst withNodeConfig = require('next-plugin-node-config');\n\nmodule.exports = withNodeConfig();\n```\n\nWith existing Next.js config:\n\n```js\nconst withNodeConfig = require('next-plugin-node-config');\n\nmodule.exports = withNodeConfig({\n  // These will be merged on top of anything that comes from `config`!\n  serverRuntimeConfig: {\n    secret: 'entropy9'\n  },\n  publicRuntimeConfig: {\n    api: '/graphql'\n  },\n  webpack(config, options) {\n    // ...\n    return config;\n  }\n});\n```\n\nUsing the `nodeConfigServerKey` and `nodeConfigPublicKey` options,\n`serverRuntimeConfig` and `publicRuntimeConfig` can be named something nicer in\nyour config files:\n\n```js\nconst withNodeConfig = require('next-plugin-node-config');\n\nmodule.exports = withNodeConfig({\n  nodeConfigServerKey: 'server',\n  nodeConfigPublicKey: 'public'\n});\n```\n\nIn your application, you’re still free to use the `next/config` module directly:\n\n```js\nimport getConfig from 'next/config';\n\nconst { serverRuntimeConfig, publicRuntimeConfig } = getConfig();\n```\n\n…but you can now use `config` as well!\n\n```js\nimport config from 'config';\n\nconst secret = config.get('serverRuntimeConfig.secret');\nconst api = config.get('publicRuntimeConfig.api');\n\n// …or if using the custom keys as in the example above:\nconst secret = config.get('server.secret');\nconst api = config.get('public.api');\n```\n\n[node-config]: https://github.com/lorenwest/node-config\n[next-config]: https://github.com/zeit/next.js#exposing-configuration-to-the-server--client-side\n[files]: https://github.com/lorenwest/node-config/wiki/Configuration-Files\n[get]: https://github.com/lorenwest/node-config/wiki/Common-Usage#using-config-values\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexogen%2Fnext-plugin-node-config","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexogen%2Fnext-plugin-node-config","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexogen%2Fnext-plugin-node-config/lists"}