Skip to content

Instantly share code, notes, and snippets.

@daniepetrov
Created July 9, 2019 14:33
Show Gist options
  • Save daniepetrov/14b28f11ed7ee49a1e6063b245c78e6f to your computer and use it in GitHub Desktop.
Save daniepetrov/14b28f11ed7ee49a1e6063b245c78e6f to your computer and use it in GitHub Desktop.
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