Big News: Socket Selected for OpenAI's Cybersecurity Grant Program.Details
Socket
Book a DemoSign in
Socket

@builtwithjavascript/server-side-config

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@builtwithjavascript/server-side-config

Hook useServerSideConfig to more easily load json files with strongly typed configuration models for use in Nuxt, Next, Node, etc on the server side

Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
11
83.33%
Maintainers
1
Weekly downloads
 
Created
Source

server-side-config

Hook useServerSideConfig to more easily load json files with strongly typed configuration models for use in Nuxt, Next, Node, etc on the server side

@builtwithjavascript/server-side-config

Hook useServerSideConfig to more easily load json files with strongly typed configuration models for use in Nuxt, Next, Node, etc on the server side

npm version

code base

TypeScript

Description

Contains hooks:

  • useServerSideConfig

How to use

install:

npm i -D @builtwithjavascript/server-side-config

consume:

// create the TypeScript interface that will define the structure of your config file
// and save it under your model or other directory ('./your-path-to-your-iconfig-model'):
// for example: 
interface IConfig {
  name: string,
  marketing: {
    title: string
    hero: string
  },
  meta: {
    title: string
    description: string
  }
}

// create a json file named app1.json that adheres to the above interface and save it 
// under a directory on your project (by default the hook will look into ./config/config-files/):
{
  "name": "for-unit-tests-only",
  "marketing": {
    "title": "For unit-tests only",
    "hero": "An example for the config file."
  },
  "meta": {
    "title":  "For unit-tests only",
    "description": "An example for the config file."
  }
}

// in the code where you need to consume the server-side config file (i.e. in Nuxt this would be in nuxt.config.ts), import a reference to the useServerSideConfig hook and your IConfig interface:
import { useServerSideConfig } from '@/server-side-config/'
import type { IConfig } from './your-path-to-your-iconfig-model'

// then load the server-side config file using the useServerSideConfig and passing the app key, in this case 'app1'
const instance = useServerSideConfig<IConfig>('app1')

// the default base directory for your json files is /config/config-files/ 
// but you could optionally specify a different path by passing this as the second arugment:
const configFilesDirectoryPath = `../my-config-files/`
const instance = useServerSideConfig<IConfig>('app1', configFilesDirectoryPath)

Keywords

config, configuration, server side, server-side, large scale apps, nuxt, next, node

FAQs

Package last updated on 21 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts