Socket
Socket
Sign inDemoInstall

config-cjs

Package Overview
Dependencies
0
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    config-cjs

Configure your node app on much cleaner and simpler way


Version published
Maintainers
1
Install size
5.41 kB
Created

Readme

Source

Make your node configuration easier

You can configure in different environment such as development, production,test,staging and etc... If the environment is not defined the default will be development

To specify the environment create a file with this format {environment}.js in your config folder

if you use config package before, it has similarity of the file structure

What's make this stand-out

  • Lightweight (< 1kb)
  • Predictable
  • Very Fast (No parsing behind the scenes)
  • No Dependencies
  • Very Straightforward
  • No need to call a function

Installation

npm i config-cjs

Usage

You need to create a config/ folder in your working directory

/config/default.js

export default {
  appName: '<Your App name>',
}

/config/production.js

export default {
  dbConfig: {
    host: process.env.DB_HOST,
    pass: process.env.DB_PASS,
  },
}

You can also use commonjs module.exports

process.env.NODE_ENV = "production"

const config = require("config-cjs")

console.log(config.appName) //<Your App name>

db.connect(config.dbConfig).then(()=>......)

You can also use the dotenv alongside with this

require("dotenv").config();

const config = require("config-cjs")

console.log(config.appName) //<Your App name>

db.connect(config.dbConfig).then(()=>......)

Don't use import or require inside the config file otherwise it will not work as your expected


How to change the config directory ?

@default /config

process.env['CONFIG_CJS-DIR'] = '/configuration'

How to debug if the result is not as expected ?

@default false

process.env['CONFIG_CJS_DEBUG'] = true

// Open the console and see the message

Keywords

FAQs

Last updated on 23 Feb 2021

Did you know?

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc