# Questions about hugo environment variables

**URL:** https://discourse.gohugo.io/t/questions-about-hugo-environment-variables/17865
**Category:** support
**Created:** [March 31, 2019, 7:49am UTC](https://discourse.gohugo.io/t/questions-about-hugo-environment-variables/17865 "2019-03-31T07:49:51Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![numbfall](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/numbfall/32/6580_2.png) [@numbfall](https://discourse.gohugo.io/u/numbfall)
#### Post date: [March 31, 2019, 7:49am UTC](https://discourse.gohugo.io/t/questions-about-hugo-environment-variables/17865/1 "2019-03-31T07:49:51Z")

</div>

When I run `hugo server` I see the message in console `Environment = 'development'`. I am wondering if there is a way to access it using `porcess.env.HUGO_ENV` for example?

Or is it just to be used inside Hugo engine like `if (eq hugo.Environment "development")`?

In Windows I use command `set HUGO_ENV=development&& hugo server`. Then I am able to access it in `postcss.config.js` via `process.env.HUGO_ENV`. This works but it is not cross-platform friendly unless I use cross-env library or something like that.

---

<div class="post-metadata">

### Author: ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)
#### Post date: [March 31, 2019, 11:45am UTC](https://discourse.gohugo.io/t/questions-about-hugo-environment-variables/17865/2 "2019-03-31T11:45:52Z")

</div>

You can pass one of these flags `-e`, `--environment`, followed by which environment you want  
Also see

> **[hugo](https://gohugo.io/commands/hugo/)**
>
> hugo hugo builds your site
> Synopsis hugo is the main command, used to build your Hugo site.
> Hugo is a Fast and Flexible Static Site Generator built with love by spf13 and friends in Go.
> Complete documentation is available at http://gohugo.io/.
> hugo...

---

<div class="post-metadata">

### Author: ![numbfall](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/numbfall/32/6580_2.png) [@numbfall](https://discourse.gohugo.io/u/numbfall)
#### Post date: [March 31, 2019, 3:05pm UTC](https://discourse.gohugo.io/t/questions-about-hugo-environment-variables/17865/3 "2019-03-31T15:05:30Z")

</div>

I wish you would have queried me, if I was unable to make my question clear, instead of linking the whole documentation.

Not what I was looking for.

Thank you for your time.

---

<div class="post-metadata">

### Author: ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)
#### Post date: [March 31, 2019, 4:28pm UTC](https://discourse.gohugo.io/t/questions-about-hugo-environment-variables/17865/4 "2019-03-31T16:28:35Z")

</div>

> [@numbfall](#):
>
> Not what I was looking for.

He was trying to help (and he pointed you to the `hugo` command, not the “whole documentation”), be grateful and be polite.

So,

You can set it via either

- `HUGO_ENVIRONMENT` os variable
- `--environment` flag

You can get it with `hugo.Environment`. Note that the defaults are `development` for server and `production` for regular `hugo`.

---

<div class="post-metadata">

### Author: ![numbfall](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/numbfall/32/6580_2.png) [@numbfall](https://discourse.gohugo.io/u/numbfall)
#### Post date: [April 1, 2019, 4:35am UTC](https://discourse.gohugo.io/t/questions-about-hugo-environment-variables/17865/5 "2019-04-01T04:35:34Z")

</div>

When `hugo server` is running, is there a way to check the default (production) environment Hugo is on from the os?

To rephrase: Lets say `hugo server` is running. Will I be able to get `process.env.HUGO_ENVIRONMENT === 'production'` to be true in webpack or gulp?

I have concluded it is not possible. I started this post to check if i had missed something.

---

<div class="post-metadata">

### Author: ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)
#### Post date: [April 1, 2019, 6:46am UTC](https://discourse.gohugo.io/t/questions-about-hugo-environment-variables/17865/6 "2019-04-01T06:46:23Z")

</div>

Use getenv

---

<div class="post-metadata">

### Author: ![numbfall](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/numbfall/32/6580_2.png) [@numbfall](https://discourse.gohugo.io/u/numbfall)
#### Post date: [April 1, 2019, 8:08am UTC](https://discourse.gohugo.io/t/questions-about-hugo-environment-variables/17865/7 "2019-04-01T08:08:33Z")

</div>

I apologise to both of you @zwbetz. I think I am being incomprehensible with my question.

> Use getenv

getenv is a Hugo only command. I was looking to use something similar to getenv in webpack, gulp, postcss processes, while hugo server is running in a project…

Again, I’m sorry.

What I want can already be achieved by manually setting a custom variable in os.

```auto
// Windows example
set HUGO_ENV=development&& hugo server

```

```auto
// retrieve HUGO_ENV
process.env.HUGO_ENV === 'development' // returns true

```

---

<div class="post-metadata">

### Author: ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)
#### Post date: [April 1, 2019, 8:24am UTC](https://discourse.gohugo.io/t/questions-about-hugo-environment-variables/17865/8 "2019-04-01T08:24:41Z")

</div>

> [@numbfall](#):
>
> I think I am being incomprehensible with my question.

You are. I think if you explain what you want to do on a more general level, it may help.

---

<div class="post-metadata">

### Author: ![brianhatchet](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/brianhatchet/32/15926_2.png) [@brianhatchet](https://discourse.gohugo.io/u/brianhatchet)
#### Post date: [January 3, 2022, 3:18pm UTC](https://discourse.gohugo.io/t/questions-about-hugo-environment-variables/17865/9 "2022-01-03T15:18:14Z")

</div>

Found this thread searching for a similar answer.

hugo.Environment taps into that build mode:

```auto
{{ printf "%#v" hugo.Environment }}

```

Useful for development mode only partials.

---

<div class="post-metadata">

### Author: ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)
#### Post date: [January 3, 2022, 3:25pm UTC](https://discourse.gohugo.io/t/questions-about-hugo-environment-variables/17865/10 "2022-01-03T15:25:02Z")

</div>

> [@brianhatchet](#):
>
> Useful for development mode only partials.

We also have:

```auto
{{ if hugo.IsProduction }}
{{ end }}

```

(which uses hugo.Environment behind the scenes)

---

<div class="post-metadata">

### Author: ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)
#### Post date: [January 5, 2022, 3:25pm UTC](https://discourse.gohugo.io/t/questions-about-hugo-environment-variables/17865/11 "2022-01-05T15:25:43Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
