Is it possible to initialize static readonly class field with env variable in Express using Typescript? I use .env file.
My code currently looks like this:
class Foo {
private static readonly port: number = process.env.PORT!;
public static getStaticPort() {
return this.port; // undefined
}
public static getProcessPort() {
return process.env.PORT; // 42
}
}
When i call Foo.getStaticPort() it gives me undefined.