node.jsexpressnx-workspace

How to get environment configuration from nx workspace from express


In my nx-workspace it has 2 environment.ts files as environment.ts and environment.prod.ts

I am trying to get the base url of environment.ts. (which is development) but i could not able to get. what is the correct way to get it?

my try for console:

const server = app.listen(port, () => {
  console.log(process.env.MONGO_URL); //undefined
  console.log('Listening at http://localhost:' + port + '/api');
}); 

environment.ts file:

export const environment = {
  production: false,
  MONGO_URL:
    'mongodb+srv://nupdayu.mongodb.net/clinics',
};

so what is the correct way to get the current env values?


Solution

  • I just imported the environment file, it woks fine.

    import { environment } from './environments/environment';
    
    const server = app.listen(port, () => {
      console.log(environment.MONGO_URL);
      console.log('Listening at http://localhost:' + port + '/api');
    });