title: How to extract environment variable from process.environment in nodejs
body: <p>I have successfully integrated stripe payments in my dummy nodejs project. But still I'm left with an issue which doesn't let me move forward as I have to push code to my github repository. So, I installed dotenv package through npm and created a .env file for storing my stripe secret key. If I extract stripe secret key using process.env.STRIPE_SECRET_KEY payment fails but If I pass STRIPE_SECRET_KEY directly payment succeeds.</p>
  
  <p>I have even consoled process.env and it does show my stripe secret key.</p>
  
  <p>This is my server.js file: </p>
  
  <pre><code>const express = require('express');
  const bodyParser = require('body-parser');
  const dotenv = require('dotenv');
  const cors = require('cors');
  
  const payments = require('./routes/api/payment');
  
  dotenv.config();
  
  const app = express();
  app.use(bodyParser.urlencoded({ extended: false }));
  app.use(bodyParser.json());
  
  app.use(cors())
  
  app.use('/api/payments', payments);
  
  app.get('/', (req, res) =&gt; res.send('hello'));
  
  const port = process.env.PORT || 3001;
  
  app.listen(port, () =&gt; console.log(`server running on port: ${port}`));
  </code></pre>
  
  <p>This is my payment.js file:</p>
  
  <pre><code>const express = require('express');
  const stripe = require('stripe') (process.env.STRIPE_SECRET_KEY); // this 
                                                         gives network error
  const stripe = require('stripe') ("sk_test_O5le6FijZU4KcoxE4"); // this 
                                                             works gracefully
  const router = express.Router();
  
  router.get('/', (req, res) =&gt; {
    res.json({
     message: 'Payment gateway works',
     time: Date.now
    });
  })
  
  router.post('/', (req, res) =&gt; {
    const credentials = {
    source: req.body.token.id,
    amount: req.body.amount,
    currency: "usd",
    description: req.body.description
  }
  
  stripe.charges.create(credentials, (err, response) =&gt; {
    if (err) {
    return res.status(400).json({ message: err })
     }
    return res.status(200).json({ message: response })
    })
  
    })
  
  module.exports = router;
  </code></pre>
  
  <p>This is my .env file:</p>
  
  <pre><code>STRIPE_SECRET_KEY = sk_test_O5le6FijZU4KcoxE4
  </code></pre>
  
  <p>directly passing stripe secret key to the stripe works but it fails if I provide stripe secret key using process.env.STRIPE_SECRET_KEY.
  I want process.env.STRIPE_SECRET_KEY to work so that I can push code to my github repository safely and securely.</p>