Q: redis port and host undefined even though env are set I am using the redis npm package and whenever I try to connect to it, it's saying the host and port are undefined. I print out my process.env object and I can see that the host and port have values set. It's only when I pass the values into my constructor for my Redis model class, that it becomes undefined. Any ideas?
index.js
require('dotenv').config()


function startRedis() {
    const redisInstance = new Redis(
        process.env.REDIS_HOST,
        process.env.REDIS_PORT
    );
    
    redisInstance.init();
}



class Redis {
        constructor(redishost, redisport) {
            this.redishost = redishost;
            this.redisport = redisport;
        }
    
        async init() {
            try {
                this.redisClient = redis.createClient({
                    port: this.redisport, 
                    host: this.redishost
                });
                
            console.log("port: ", this.port)
            console.log("host: ", this.host)
    
            } catch(error) {
                console.log(`Error creating client due to: ${error}`)
            }
}

.env
REDIS_HOST="value here"
REDIS_PORT="port value here"

package.json
{
  "name": "app",
  "version": "0.0.1",
  "dependencies": {
    "redis": "^3.0.2",
    "dotenv": "^10.0.0"
  },
  "engines": {
    "node": ">=10.0.0"
  },
  "main": "index.js",
  "keywords": [],
  "author": "",
  "license": "ISC",
  "description": "",
  "devDependencies": {
    "redis": "^3.0.2",
    "dotenv": "^10.0.0"
  }
}

Update 1: Added my package.json

A: As I can see here if process.env.REDIS_HOST having value.
You have new on wrong class name
Your start function should be like

function startRedis() {
    const redisInstance = new Redis(
        process.env.REDIS_HOST,
        process.env.REDIS_PORT
    );
    
    redisInstance.init();
}

And you are console.log wrong value

class Redis {
        constructor(redishost, redisport) {
            this.redishost = redishost;
            this.redisport = redisport;
        }
    
        async init() {
            try {
                this.redisClient = redis.createClient({
                    port: this.redisport, 
                    host: this.redishost
                });
                
            console.log("port: ", this.redisport)
            console.log("host: ", this.redishost)
    
            } catch(error) {
                console.log(`Error creating client due to: ${error}`)
            }
}

