<p>I have a nodeJS api services  and .env file with some configuration.</p>
<p>Currently, in my local environment I can run my service. I read the .env file on startup and access the value via process.env.[name] command</p>
<pre><code>const myEnv = dotenv.config({ path: path.resolve(path.join(__dirname, '/configuration/.env')) });
dotenvExpand(myEnv);
</code></pre>
<p>This is my setting in my deployment yaml file</p>
<pre><code> envFrom:
         - configMapRef:
             name: jobs-nodeapi-qa--configmap
</code></pre>
<p>I create a configMap in GCP and deploy. How do I change my code so that it read from the config map</p>
<p>Thanks</p>

user2570135
<p>No need to change your code which refer to the .env file. Since you have created the ConfigMap, you can then mount it to the correct path that your code expected it to be.</p>
<p>Create the ConfigMap:</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: env
data:
  .env: |
    key=value
</code></pre>
<p>Use it in the pod:</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: busybox
  labels:
    app: busybox
spec:
  volumes:
  - name: env
    configMap:
      name: env
  containers:
  - name: busybox
    image: busybox
    command:
    - sh
    - -c
    - while :; do cat /configuration/.env; sleep 1; done
    volumeMounts:
    - name: env
      mountPath: /configuration # update this path to the path your app expects
</code></pre>
<p>A simple usage above is output the .env content every second.</p>
