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

207
Visualizações
how to set environment variable from terminal in windows

I am following a node course and while setting the environment variable as shown it does not work

It says to set environment variables, use SET on Windows and EXPORT on Mac:

set jwtkey=myprivatekey, when I use this nothing happens, it does not set anything.

This is set using the config package, and I have also created a separate files for default.json and custom-env.json

if (!config.get("jwtPrivateKey")) {
    console.error("FATAL ERROR: JwtKey Not Set");
    process.exit(1);
}

please help

this is my .env file(using dotenv)

PORT=9000 //this is working
jwtPrivateKey="myPrivateKey" //this is not working tho.

[basically, I wanted to hide my VERIFY SIGNATURE(digital signature) and store it in ENV so that it cant be accessed.]

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I would do it differently.

  1. Create a .env file in your server root.

  2. Add the key/value pair:

    JWT_PRIVATE_KEY="936392a8c..."
    
  3. Install dotenv, and import it.

  4. Access process.env.JWT_PRIVATE_KEY from anywhere in your server app.

(based on this article.)

about 4 years ago · Juan Pablo Isaza Relatório

0

If you use set in a Windows terminal, it will set the variable just for this terminal. If you start the node in the same terminal, everything should work fine. Otherwise read this article on how to change the variable permanently.

There are two types of environment variables in Windows: user and system variables. If possible, use a user variable.

You might want to read the answers to this similar question

Update (.env)

When using dotenv to read an .env-file as suggestd by Andy, be aware of the parsing rules and make sure that the file encoding is correct; see answers to What language is a .env file written in?.

Be sure that you use the same variable name in .env and in your code and comments. (You did use jwtkey, JwtKey and jwtPrivateKey.) I also recommend that you use UPPER_CASE for environment variables, just to make sure that case does not matter when switching operating systems. Using the same conventions as the node.js documentation is always a good idea. (How to read environment variables from Node.js.)

about 4 years ago · Juan Pablo Isaza Relatório
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