{"id":14155857,"url":"https://github.com/builtwithjavascript/server-side-config","last_synced_at":"2025-08-06T02:30:42.903Z","repository":{"id":218377040,"uuid":"746272465","full_name":"builtwithjavascript/server-side-config","owner":"builtwithjavascript","description":"Hook useServerSideConfig to more easily load json files with strongly typed configuration models for use in Nuxt, Next, Node, etc on the server side","archived":false,"fork":false,"pushed_at":"2024-04-23T13:52:34.000Z","size":98,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-04-23T14:38:30.186Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/builtwithjavascript.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-21T15:30:46.000Z","updated_at":"2024-07-12T01:43:00.446Z","dependencies_parsed_at":null,"dependency_job_id":"a18a7f33-6c9c-4e7e-b107-a7719aa3f30a","html_url":"https://github.com/builtwithjavascript/server-side-config","commit_stats":null,"previous_names":["builtwithjavascript/server-side-config"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/builtwithjavascript%2Fserver-side-config","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/builtwithjavascript%2Fserver-side-config/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/builtwithjavascript%2Fserver-side-config/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/builtwithjavascript%2Fserver-side-config/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/builtwithjavascript","download_url":"https://codeload.github.com/builtwithjavascript/server-side-config/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228829001,"owners_count":17978129,"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":[],"created_at":"2024-08-17T08:05:03.111Z","updated_at":"2025-08-06T02:30:42.886Z","avatar_url":"https://github.com/builtwithjavascript.png","language":"TypeScript","readme":"# @builtwithjavascript/server-side-config\n\n[![npm version](https://badge.fury.io/js/@builtwithjavascript%2Fserver-side-config.svg)](https://badge.fury.io/js/@builtwithjavascript%2Fserver-side-config)\n\nHook `useServerSideConfig` to more easily load JSON files with strongly typed configuration models for use in Node.js environments (including frameworks like Nuxt, Next.js, etc.) on the server side.\n\n## Codebase\nTypeScript\n\n## Description\nThis package provides a single hook:\n- `useServerSideConfig`\n\n## How to use\n\n### IMPORTANT: This package should be installed as a local dependency (not globally) as it is designed for project-specific server-side configuration loading.\n\n### Installation:\n```bash\nnpm i -D @builtwithjavascript/server-side-config\n```\n\n\n\n### Consumption:\n\n1. **Define your Configuration Model:** Create a TypeScript interface that defines the structure of your configuration file. Save it in your models directory or a suitable location (e.g., `./your-path-to-your-iconfig-model.ts`):\n\n   TypeScript\n\n   ```\n   // your-path-to-your-iconfig-model.ts\n   interface IConfig {\n     name: string,\n     marketing: {\n       title: string\n       hero: string\n     },\n     meta: {\n       title: string\n       description: string\n     }\n   }\n   ```\n\n2. **Create your JSON Configuration File:** Create a JSON file (e.g., `app1.json`) that adheres to your defined interface. By default, `useServerSideConfig` will look for config files within a directory you specify. A common convention is `config/config-files/`.\n\n   Example `app1.json`:\n\n   JSON\n\n   ```\n   {\n     \"name\": \"for-development\",\n     \"marketing\": {\n       \"title\": \"My Awesome App\",\n       \"hero\": \"The best app ever!\"\n     },\n     \"meta\": {\n       \"title\":  \"My App Title\",\n       \"description\": \"A description of my awesome app.\"\n     }\n   }\n   ```\n\n3. **Integrate and Load the Configuration:** In your server-side code (e.g., `nuxt.config.ts`, API routes, Node.js server scripts), import the `useServerSideConfig` hook and your `IConfig` interface.\n\n   **Crucially, you must provide the `configFilesDirectoryPath` argument.** This path should be **relative to the root of your project** (where your `package.json` resides, and where your Node.js process is typically started, i.e., `process.cwd()`).\n\n   TypeScript\n\n   ```\n   import { useServerSideConfig } from '@builtwithjavascript/server-side-config'\n   import type { IConfig } from './your-path-to-your-iconfig-model' // Adjust this path to your model\n   \n   // Example 1: Using a hardcoded app key (for specific scenarios or testing)\n   const config = useServerSideConfig\u003cIConfig\u003e('app1', 'config/config-files');\n   console.log(config.name); // Output: \"for-development\"\n   \n   // Example 2: Using an environment variable for the app key (recommended for dynamic environments)\n   // Assuming your config files are in 'config/config-files/' relative to your project root\n   const configFilesDir = 'config/config-files';\n   \n   // In Nuxt, this might be used in nuxt.config.ts for server-side operations\n   // or in server/api routes.\n   const instance = useServerSideConfig\u003cIConfig\u003e(process.env.SITE_KEY, configFilesDir);\n   \n   // Note: The `configFilesDir` parameter MUST be a path that `fs.readFileSync` can resolve\n   // relative to the current working directory (`process.cwd()`) of your running Node.js process.\n   // For most Nuxt/Next.js/Node projects, 'config/config-files' will be correct if your\n   // config files are directly within a 'config/config-files' folder at your project root.\n   ```\n\n## Development Dependencies:\n\n- `@types/jest`\n- `@types/node`\n- `jsdom`\n- `prettier`\n- `ts-node`\n- `typescript`\n- `vite`\n- `vitest`\n","funding_links":[],"categories":["others"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbuiltwithjavascript%2Fserver-side-config","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbuiltwithjavascript%2Fserver-side-config","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbuiltwithjavascript%2Fserver-side-config/lists"}