Skip to content

EcommElite/node-laravel-style-config

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node Laravel Style Config

Provides Laravel style config() and env() methods utilizing .env

Installation

npm install git+https://github.com/EcommElite/node-laravel-style-config.git#master npm install git+https://git@github.com/EcommElite/node-laravel-style-config.git --save

3b13fdba3647931106a7810132b54c77eacd1c70

Usage

import { env } from 'node-laravel-style-config';

let value = env('APP_NAME', 'Default');
// will return the APP_NAME value in .env if present, or "Default"
import { env, config, setConfig } from 'node-laravel-style-config';

setConfig({
    app: {
        name: env('APP_NAME', 'default'),
    }
});

let value = config('app.name');
// will return the APP_NAME value in .env if present, or "Default"

Setup

The typical setup is to create a config directory, then inside that put a config.js helper and your config files.

config.js

import { config, setConfig } from 'node-laravel-style-config';
import app from './app';
import database from './database';

setConfig({

    app,
    database

});

export default config;

app.js

import { env } from 'node-laravel-style-config';

export default {

    name: env('APP_NAME', 'Default App Name')

}

database.js

import { env } from 'node-laravel-style-config';

export default {

    host: env('DATABASE_HOST', '127.0.0.1')
    port: env('DATABASE_PORT', '3306')
    username: env('DATABASE_USERNAME', 'root')
    password: env('DATABASE_PASSWORD', '')

}

Which can then get used like this

import config from './config/config';

let db_username = config('database.username'); // root

About

Laravel style config() and env() methods utilizing .env

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published