<p>I have a react app running in node with serverside rendering.
The following environment variable is set to <code>test</code> through kubernetes in my test environment: <code>process.env.NODE_ENV</code>.</p>

<p>When I run the following two commands they give different results. I expect the value to always be <code>test</code>. </p>

<pre><code>log.debug(process.env.NODE_ENV) // logs development
log.debug(eval('process.env.NODE_ENV')) // logs test
</code></pre>

<p>Somehow, it looks like the variable is first interpreted as <code>development</code> (Which can happen in my code if it is undefined), but it is somehow interpreted correctly to <code>test</code> by the <code>eval()</code> function.</p>

<p>What can cause node to interpret the value differently between the two expressions?</p>

<p>EDIT: Added kubernetes yaml config.<br>
The ${} variables are replaced by Azure DevOps during the release process.</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: config
  namespace: ${KUBERNETES_NAMESPACE}
data:
  NODE_ENV: ${NODE_ENV}
---
kind: Service
apiVersion: v1
metadata:
  name: ${SERVICE_NAME}
spec:
  selector:
    app: ${SERVICE_NAME}
  ports:
  - name: http
    protocol: TCP
    port: 80
    targetPort: 3000

  loadBalancerIP: ${IP_NUMBER}
  type: LoadBalancer


---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: ${SERVICE_NAME}
  labels:
    app: ${SERVICE_NAME}
spec:
  replicas: 2
  selector:
    matchLabels:
      app: ${SERVICE_NAME}

  template:
    metadata:
      labels:
        app: ${SERVICE_NAME}
    spec:
      containers:
      - name: ${SERVICE_NAME}
        image: {IMAGE_PATH}/${IMAGE_REPO}:${BUILD_NUMBER}
        ports:
        - name: http
          containerPort: 3000
          protocol: TCP
        resources: 
          limits:
            cpu: 100m
            memory: 1024Mi
          requests:
            cpu: 100m
            memory: 1024Mi
        envFrom:
        - configMapRef:
            name: config

      imagePullSecrets: 
      - name: ${IMAGEPULLSECRETNAME}
</code></pre>

Jakob S. Rames
<p>I seem to have found the cause of the issue.<br>
We use webpack for bundling (which I maybe should have mentioned), and in the server code webpack has outputted, I see that it has resolved <code>process.env.NODE_ENV</code> to a static value, but it doesn't do the same for <code>eval(process.env.NODE_ENV)</code>.<br>
Seems my post was unecessary, but I hope it might help someone in the future.</p>
