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

172
Vistas
Can't reach env from React Component in Next.js

I have a Next.js project. I have created .env file and using enviroments from this file in server.js file. But when I want to reach these enviroments from component, I can't access. What should I do?

This is .env file:

SERVER_PORT=3000
DOMAIN=127.0.0.1
DATABASE=dburl

This is server.js file:

require('dotenv/config')

const port = process.env.SERVER_PORT || 3000
server.listen(port, (err) => {
      if(err) throw err
      console.log(`Server listen on http://127.0.0.1:${port}`)
    })

This is any component of react:

axios
    .get(`http://${process.env.DOMAIN}/api/improve-language`)
    .then(res => {
      ...
    })
    .catch(err =>{
      console.log(err)
    })
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Based on the documentation if you want to use the env variables in the browser, they must be named with prefix NEXT_PUBLIC_.

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