menu

Questions & Answers

Cannot access properties of process when using it in object value

I am trying to use process.env in value of a key in ts. But I am not able to access process properties and its showing "Cannot find namespace 'prcoess'".

const MAIL_SETTINGS: {
    service: 'gmail',
    auth: {
      user: prcoess.env.MAIL_EMAIL,
      pass: prcoess.env.MAIL_PASSWORD,
    },
  }

i tried to make process as a global variable and used it in value but didnt work.

Answers(1) :

I think there is typo in your code. Also, a technical aspect regarding import is missing. Like this.

require('dotenv').config() // requiring dotenv module
console.log(process.env)  // logging on screen to confirm

const MAIL_SETTINGS: {
service: 'gmail',
auth: {
  user: process.env.MAIL_EMAIL,   // use process.env
  pass: process.env.MAIL_PASSWORD,
},

}

Also, for the .env file. It should be structured like this.

MAIL_EMAIL=test@test.com
MAIL_PASSWORD=test