Socket
Book a DemoInstallSign in
Socket

@apparts/config

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@apparts/config

A config-loading framework

1.4.1
latest
npmnpm
Version published
Maintainers
1
Created
Source

#+TITLE: @apparts/config #+DATE: [2019-02-07 Thu] #+AUTHOR: Philipp Uhl

  • Usage

This package can read configuration from environment variables, or, if not found in, from the folder =config= in the root-directory of the project.

** As environment variable

Storage in an environment variable can be done in two ways:

  • as a string that is parsable by JSON.parse
  • as a Base-64 encoded string that decodes to a JSON.parse-parsable string

** From a folder when running in a Node environment

To require a configuration that is stored in one of the files

  • =config/my-color.json=
  • =config/my-color.js= or the environment variable =MY_COLOR= (note, a dash becomes an underscore and everything is in uppercase): #+BEGIN_SRC sh const Colors = require('apparts-config').get('my-color'); #+END_SRC

** Webpack for web environment

To require a configuration that is stored in the environment variable =MY_COLOR= (note, a dash becomes an underscore and everything is in uppercase): #+BEGIN_SRC sh const Colors = require('apparts-config').get('my-color'); #+END_SRC

In order to create environment variables use the following webpack (v

2.0) configuration options:

#+BEGIN_SRC js module.exports = env => { return { plugins: [ new webpack.DefinePlugin({ 'process.env': { 'MY_COLOR': JSON.stringify(JSON.stringify(require('./src/utils/colors.js'))) } }), ] } }; #+END_SRC

** React environment

In an react environment, you must call at the beginning of your application the following code. That ensures, that @apparts/config can access the environment variables.

#+BEGIN_SRC js import { setEnv } from "@apparts/config"; setEnv(process.env); #+END_SRC

Your config variables need to be stored in the =.env= file, with all config names prefixed with =REACT_APP_= or =VITE_=.

E.g. to get the config =my-color= you must store =REACT_APP_MY_COLOR= in your =.env= file. You can store the values as raw string or base64 encoded.

FAQs

Package last updated on 01 Apr 2025

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

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.