Throughout December we’ll be highlighting a different Netlify feature each day. It might just be the thing you need to unlock those creative juices, and dust off that domain you registered but never deployed! Keep an eye on the blog and on Twitter for each feature!
As you’ll see in this post, Netlify supports environment variables in your projects (including centrally managed team environment variables for use across all of your team’s projects). A great feature of the Netlify CLI is that it lets you manage your project’s environment variables without leaving your terminal, and can even make them available to your local development environment without the need for libraries or .env files.
Here are a few tips.
You’ll first need to make sure that you have the Netlify CLI installed, and that you’ve linked your local project to a Netlify site.
# Install the Netlify CLI for use anywhere on your systemnpm install -g netlify-cli# Link your the current folder to an existing Netlify projectnetlify link
# ...or create and link a new project in Netlifynetlify initNow you can start managing the environment variables for the project.
Create or update an environment variable
# Set the value of an environment variable, creating it if needednetlify env:set MY_ENV_VAR "some value"Check the value of an environment variable
# Get the value of an environment variablenetlify env:get MY_ENV_VARDelete an environment variable
# Delete an environment variablesnetlify env:unset MY_ENV_VARListing all environment variables
# List all the environment variables available to this projectnetlify env:listImport environment variables from a file
# Import many environment variables from a local filenetlify env:import .envAccessing environment variables during local development
Here’s another place where Netlify Dev (bundled as part of the Netlify CLI) really shines. When you use Netlify Dev to run your project, it will automatically make your environment variable available to your code with process.env.VARIABLE_NAME. Just the same as when the code runs in Netlify Build or your serverless Netlify Functions.
# Detect, run, and your build,# with all of your environment variablesnetlify dev
