Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

326
Visualizações
How to use an environment variable in a Nuxt.js project for a file that is not injected as plugin?

I have a file in my Nuxt.js project that simply resides in the src directory. Therefore it is not in the convention of a Nuxt project. Therefore I understand that environment variables defined in the nuxt.config.js will not appear in the file placed in src.

However I'd still like to use environment variables in that mentioned file. This is how I try to access the environment variable:

const GAMESERVER_URL = process.env.GAMESERVER_URL || 'http://localhost:1001'

Unfortunately it always falls back to the default value http://localhost:1001. I have another file used as Nuxt.js plugin that is referencing the very same environment variable with the exact same statement (above). The plugin file works fine and is using the environment variable correctly.

What are my options to also introduce the environment variables to my standalone file in the src directory?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda