Finally, an edge runtime that works out-of-the-box with Next.js, Remix, Nuxt, and more. Check it out!

Guides & Tutorials

More tips for environment variables and Netlify CLI

Guides & Tutorials

More tips for environment variables and Netlify CLI

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 system
npm install -g netlify-cli
# Link your the current folder to an existing Netlify project
netlify link

# ...or create and link a new project in Netlify
netlify init

Now 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 needed
netlify env:set MY_ENV_VAR "some value"

Check the value of an environment variable

# Get the value of an environment variable
netlify env:get MY_ENV_VAR

Delete an environment variable

# Delete an environment variables
netlify env:unset MY_ENV_VAR

Listing all environment variables

# List all the environment variables available to this project
netlify env:list

Import environment variables from a file

# Import many environment variables from a local file
netlify env:import .env

Accessing 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 variables
netlify dev

More information

Keep reading

Recent posts

Book cover with the title Deliver web project 10 times faster with Jamstack enterprise

Deliver web projects 10× faster

Get the whitepaper