0

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.

2 Answers2

0

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
Shamoon97
  • 332
  • 2
  • 12
0
  1. You had a typo prcoess => process
  2. Not sure how your envs were loaded, it could be provided either via dotenv or other mechanisms. Why dotenv is unnecessary
  3. process is already a global variable, thus there seems no need to declare it again. If interested, please see this article.
Shiou-Ju
  • 11
  • 1