Last active
August 27, 2019 19:47
-
-
Save dilverdev/fde68965add8469d671c1ee28bc85cea to your computer and use it in GitHub Desktop.
Configuration env in javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const envConfig = { | |
development: { | |
SITE_URL: 'http://localhost:3000', | |
API_URL: 'http://localhost:3000/api' | |
}, | |
testing: { | |
SITE_URL: 'https://test.site.com', | |
API_URL: 'https://api.test.site.com' | |
}, | |
production: { | |
SITE_URL: 'https://site.com', | |
API_URL: 'https://api.site.com' | |
} | |
} | |
const currentEnv = process.env.NODE_ENV | |
export default envConfig[currentEnv] | |
/* | |
---- USE IN COMPONENETS JS ---- | |
import env from './env' | |
console.log(env.SITE_URL) | |
*/ | |
/* | |
---- RUN SCRIPTS (package.json) ---- | |
... | |
"scripts": { | |
"dev": "NODE_ENV=development ...", | |
"testing": "NODE_ENV=testing ...", | |
"build": "NODE_ENV=production ...", | |
}, | |
... | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yeah! Really minimalistic! 😄
EDIT : and it's working on both serverless and server mode !