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

878
Vistas
How to use environment variables in React with vite?

I was trying to access environment variables, at first, I got an error saying process is not defined.

Then I tried this but I'm not sure why it's not working

.env

VITE_BASE_URL="https://jikan1.p.rapidapi.com/"
VITE_HOST="jikan1.p.rapidapi.com"
VITE_KEY="abcdefghij12345678"

Page.jsx

let api = {
  base: import.meta.env.VITE_BASE_URL,
  host: import.meta.env.VITE_HOST,
  key: import.meta.env.VITE_KEY
};

function Upcoming() {
      

    console.log(api);
    return (
      <div>
      <p>{api.host}</p>
      <p>{api.base}</p>
      <p>{api.key}</p>
    </div>
)
}

I only get api.host but the base and key are undefined

can someone tell me what I'm doing wrong here?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I figured out why it's not working, silly mistake.

it's just because I didn't restart the server there is nothing wrong other than that.

if you don't stop the server and start it again,env file won't be updated.

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