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

172
Visualizações
port undefined run by npm run start

I write following code in nodeJS :

const port = process.env.port;
const app = express();
const routes = require('./routes/routes');
app.use('/', routes);
app.listen(port, console.log('your browser run on port ' + port));

when i run code by nodemon(npm run start), port variable is undefined while when i run it with node(node app.js), the port variable contains the value of the port where the program is running. Why the program run by nodemon the value of the port variable is undefined?

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

0

Export the port beforehand.

export port=8080

Additionally, use some fallback.

const port = process.env.port || "3000"

Also note, by convention, environment variables are upper cases.

export APP_PORT=8080
const port = process.env.APP_PORT || "3000"
about 4 years ago · Juan Pablo Isaza Relatório

0

If you don't have .env file create one. Write the port value in

port=8080

install the dotenv from npm

npm install dotenv

add the this line before define port variable

require('dotenv').config()
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