Skip to content

Instantly share code, notes, and snippets.

@nicnocquee
Created May 5, 2020 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicnocquee/4afe7bca35bf52fafe860606e500d1dd to your computer and use it in GitHub Desktop.
Save nicnocquee/4afe7bca35bf52fafe860606e500d1dd to your computer and use it in GitHub Desktop.
Small function to expose environment variables to nextjs app
require('dotenv').config()
const getEnvWithPrefixes = (prefixes = ['REACT_APP_', 'FIREBASE_']) => {
return Object.keys(process.env).reduce((prev, curr) => {
if (prefixes.some(p => curr.startsWith(p))) {
return {
...prev,
[curr]: process.env[curr],
}
}
return prev
}, {})
}
module.exports = {
env: getEnvWithPrefixes(),
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment