The express-generator package helps a lot in the development of web applications with Node, because it generates the skeleton of an application.

A small disadvantage is that, when generating the code, we do not know how to change some very basic things, for example, the port on which the app listens (the default port is 3000).

In this post I will show you how to change the port in some app generated by express-generator.

Change port

If you want to change the port directly in the code, go to bin/www, and search for the line that looks like this:

var port = normalizePort (process.env.PORT || '3000');

Change  ‘3000’ for the port you want

Change the port from the command line

A good practice (especially when you want to mount the app in a different environment) is to specify the port as an environment variable.

If you want to do so, before running the app, type the following command in the terminal:


In this way, process.env.PORT will be at the value of 5000 and you can change the port from the operating system.

Estoy disponible para trabajar en tu proyecto o realizar tu tarea pendiente, no dudes en ponerte en contacto conmigo.
Si el post fue de tu agrado muestra tu apoyo compartiéndolo, suscribiéndote al blog, siguiéndome o realizando una donación.

Suscribir por correo

Ingresa tu correo y recibirás mis últimas entradas sobre programación, open source, bases de datos y todo lo relacionado con informática

Relacionado:  A plugin for printing in thermal printers directly from browser

Join 496 other subscribers


Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: