Skip to content

Instantly share code, notes, and snippets.

@dilverdev
Last active August 27, 2019 19:47
Show Gist options
  • Save dilverdev/fde68965add8469d671c1ee28bc85cea to your computer and use it in GitHub Desktop.
Save dilverdev/fde68965add8469d671c1ee28bc85cea to your computer and use it in GitHub Desktop.
Configuration env in javascript
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 ...",
},
...
*/
@davidroman0O
Copy link

davidroman0O commented May 20, 2019

Yeah! Really minimalistic! 😄

EDIT : and it's working on both serverless and server mode !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment