Looking to implement a nested if else statement for importing and exporting in ES6? In this scenario, we have 2 files - production.js and development.js which contain keys for development and production code respectively. Additionally, there is another file called keys.js that imports and exports these keys based on the requirements. All 3 files are located within the same directory.
Keep in mind that package.json specifies type as "module".
production.js
const keys = {
GOOGLE_CLIENT_ID: process.env.GOOGLE_CLIENT_ID,
GOOGLE_CLIENT_SECRET: process.env.GOOGLE_CLIENT_SECRET,
mongoURI: process.env.MONGO_URI,
cookieKey: process.env.COOKIE_KEY
}
export default keys;
development.js
const keys = {
GOOGLE_CLIENT_ID: 'something.something',
GOOGLE_CLIENT_SECRET: 'itisasecret',
mongoURI: 'database',
cookieKey: 'blabla',
}
export default keys;
keys.js
if (process.env.NODE_ENV === 'production') {
/*This section throws error*/
import keys from './production.js'
export default keys
}
else{
/*This section also throws error*/
import keys from './development.js'
export default keys
}