<p>Ok i figured it out. I simply forgot to export the variables that were declared in the current shell.</p>

CC BY-SA 4.0
2022-07-04T06:19:03.083Z
2022-07-04T06:19:03.083Z
Vadzim
<p>Please help me somebody with passing variables to node app.
Given:
node app on ubuntu
package.json contains</p>
<pre><code>scripts {
    start: node index.js
}
</code></pre>
<p>The app is started with command
npm run start</p>
<p>Problem:
the app requires a ton of environment variables
the app runs on the server so i am not using .env file
variables are exported in the shell so i can verify they are available in the shell before i do npm run start like so
echo $MY_VAR
works</p>
<p>Currently in the sell that has all variables exported when i start the app i get from process.env.MY_VAR is undefined</p>
<p>PS i’d always been using .env file before but now that i want it to run on the server i have no idea what magic is needed to pass variables form current shell environment to the node app.</p>

<node.js><environment-variables>
Pass variables form current shell environment to the node app
Vadzim
# Pass variables form current shell environment to the node app

(Asked by: username_0 on 2022-07-04)

Please help me somebody with passing variables to node app.
Given:
node app on ubuntu
package.json contains
scripts {
    start: node index.js
}

The app is started with command
npm run start
Problem:
the app requires a ton of environment variables
the app runs on the server so i am not using .env file
variables are exported in the shell so i can verify they are available in the shell before i do npm run start like so
echo $MY_VAR
works
Currently in the sell that has all variables exported when i start the app i get from process.env.MY_VAR is undefined
PS i’d always been using .env file before but now that i want it to run on the server i have no idea what magic is needed to pass variables form current shell environment to the node app.

**Tags:** node.js, environment-variables


---

## 1 answers

### Answer by username_0 on 2022-07-04. Score: 0

Ok i figured it out. I simply forgot to export the variables that were declared in the current shell.


---

