Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

166
Vistas
How to read environment variable key and value dynamically in NodeJS

I would like to read all the environment variables key and value dynamically and form the array like below:

environment: [
    {
        name: 'DB_NAME',
        value: 'myDatabase'
    },
    {
        name: 'DB_USER_NAME',
        value: 'admin'
    },
    {
        name: 'DB_PASSWORD',
        value: 'admin'
    },
    {
        name: 'DB_TABLE_NAME',
        value: 'myTable'
    },
]

I'm able to print all the environment variables but I'm struggling to get the key and value and form the array dynamically - could someone please help me with this? Appreciate your help in advance. Thanks.

const env = require('dotenv').config();
var environmetList = process.env
console.log("printing env variables", environmetList)
const environment = [];
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Using Object#entries, get the list of pairs in process.env. Then, iterate over it using Array#map to get a list of objects with name and value:

Object.entries(process.env).map(([key, value]) => ({ name: key, value }))
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda