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

166
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 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