---
title: "Discussion on \"Building a Github Repo Template Part 5: Next.js Environment Variables\" | Hashnode"
description: "Discussion on \"Building a Github Repo Template Part 5: Next.js Environment Variables\". In this ongoing series, I am putting together a Github Repository Template for my \"Go To\" front-end tech stack of Next.js, React, TypeScript etc. In this installment of the series, I will get custom environment variables into our Next.js application ..."
url: "https://hashnode.com/posts/building-a-github-repo-template-part-5-nextjs-environment-variables/5f1204d3b8ea603b4afa1689"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Building a Github Repo Template Part 5: Next.js Environment Variables](https://hashnode.blainegarrett.com/building-a-github-repo-template-part-5-nextjs-environment-variables?utm_source=hashnode&utm_medium=feed)

In this ongoing series, I am putting together a Github Repository Template for my "Go To" front-end tech stack of Next.js, React, TypeScript etc. In this installment of the series, I will get custom environment variables into our Next.js application ...

Jul 17, 2020 · 10 min read · hashnode.blainegarrett.com  
Updated Mar 18, 2022  
Read the article

-   [#boilerplate](https://hashnode.com/tag/boilerplate)
-   [#nextjs](https://hashnode.com/tag/nextjs)
-   [#reactjs](https://hashnode.com/tag/reactjs)
-   [#github](https://hashnode.com/tag/github)

## Written by

[Blaine Garrett](https://hashnode.com/@blainegarrrett)

@blainegarrrett · Minneapolis, Minnesota, USA

  
[View profile](https://hashnode.com/@blainegarrrett)

Software Engineer and Artist

I&#39;ll find something good to put here.

## Responses 1

Markdown supported · ⌘↵ to post

[Chris Weekly](https://hashnode.com/@chrisweekly)

[Mar 17, 2022](https://hashnode.com/posts/building-a-github-repo-template-part-5-nextjs-environment-variables/5f1204d3b8ea603b4afa1689/comment/6233b5c86647c71acb640ca2)

Hi [Blaine Garrett](https://hashnode.com/@blainegarrrett),  
Thanks for sharing a great writeup about a gnarly topic.

I have a minor correction to share. You wrote:

_"Note: This hierarchy optionally goes further with `.env.development` and `.env.production` (corresponding to the value of NODE\_ENV)..."_

But they don't actually correspond to the value of NODE\_ENV. Next.JS bases its decision to read from `.env.development` vs `.env.production` on one thing only: whether you start the app with `next dev` or `next start`. That's all. NODE\_ENV's value is irrelevant to that bit of Next-specific logic.

AFAICT you get the rest of the complicated picture right; hopefully my comment will inspire you to edit the post, or at least help ensure other readers aren't accidentally misled.

Slainte, Chris

[Blaine Garrett](https://hashnode.com/@blainegarrrett)

[Mar 18, 2022](https://hashnode.com/posts/building-a-github-repo-template-part-5-nextjs-environment-variables/5f1204d3b8ea603b4afa1689/comment/6233b5c86647c71acb640ca2#reply-6234a279bef4c71aa6f0e5dd)

Thanks Chris! I made the correction.

However, now that I reread the loading order docs, I'm conflicted if this is accurate. [nextjs.org/docs/basic-features/environment-variab…](https://nextjs.org/docs/basic-features/environment-variables#environment-variable-load-order)

Again, I don't use this feature often so I hesitate to dig further at the moment. I tend to explicitly add the NODE\_ENV to my command line args when running the prod build locally but it might be redundant in that `next dev` is implicitly NODE\_ENV='development' and `next start` is NODE\_ENV='production'. I'm tempted to see what `NODE_ENV='development' next start` produces. I'll have to try it out later. Anywho, thanks again for commenting and I'm glad these articles are still helping folks out after 2 years.

[Chris Weekly](https://hashnode.com/@chrisweekly)

[Mar 21, 2022](https://hashnode.com/posts/building-a-github-repo-template-part-5-nextjs-environment-variables/5f1204d3b8ea603b4afa1689/comment/6233b5c86647c71acb640ca2#reply-62390bca5df27d5ca212f672)

Right on, [Blaine Garrett](https://hashnode.com/@blainegarrrett).

FTR I did exhaustive tests including `NODE_ENV=development next start`, `NODE_ENV=production next dev`, etc -- but I'm also currently stuck on v10.2.3. Maybe this has since changed in v11 or v12.

IMHO Next.js made a rare misstep in being both opinionated and rigid about proper support for true 12-factor config that lives in the runtime deploy environment. It probably stems from their original desire to stay "close" to create-react-app, and ofc whatever most closely aligns with Vercel's preferred hosting model. (shrug)

Slainte,  
Chris

PS See also [github.com/vercel/next.js/issues/12772](https://github.com/vercel/next.js/issues/12772#issuecomment-790228350) and [github.com/vercel/next.js/discussions/25764](https://github.com/vercel/next.js/discussions/25764)
