What is the best way to access env variables on the back panel when using the angular -fullstack generator?

I am using the Yeoman angular-fullstack generator .

And I updated the server / config / environment / local.env.js file :

module.exports = {
  DOMAIN: 'http://localhost:9000',
  SESSION_SECRET: 'vfsite2-secret',
  SENDGRID : {
      API_KEY : 'my_api_key'
  },
  DEBUG: ''
};

How best can I use SENDGRID.API_KEYelse, where on my server files, like mine server/api/thing/thing.controller.js?

Note this is not a duplicate question. This is a similar question , because I want to use -side on the server.

+4
source share
2

:

server/config/environment/local.env.js:

module.exports = {
    DOMAIN: 'http://localhost:9000',
    SESSION_SECRET: 'vfsite2-secret',
    SENDGRID_API_KEY: 'my_api_key',
    DEBUG: ''
};

server/config/environment/index.js:

var all = {
  env: process.env.NODE_ENV,

  // ... other configs here

  // SendGrid connection options
  sendgrid: {
    'api_key': process.env.SENDGRID_API_KEY
  }
};

api_key sendgrid server/api/thing/thing.controller.js:

import config from '../../config/environment';

// using SendGrid Node.js Library
var sendgrid = require("sendgrid")(config.sendgrid.api_key);
+3

?

global.globalConfig = {
  DOMAIN: 'http://localhost:9000',
  SESSION_SECRET: 'vfsite2-secret',
  SENDGRID : {
      API_KEY : 'my_api_key'
  },
  DEBUG: ''
};

module.exports = global.globalConfig;
+2

Source: https://habr.com/ru/post/1623678/


All Articles