Node JS and NPM

Change express-generator app port

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:

SET PORT=5000

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


I am available for hiring if you need help! I can help you with your project or homework feel free to contact me.
If you liked the post, show your appreciation by sharing it, or making a donation

parzibyte

Freelancer programmer ready to work with you. Web, mobile and desktop applications. PHP, Java, Go, Python, JavaScript, Kotlin and more :) https://parzibyte.me/

Entradas recientes

Receipt designer for thermal printers – Free and open source

In the last months I have been working on a ticket designer to print on…

11 months hace

JavaScript: store and read files with the Origin Private File System

In this post you will learn how to use the Origin Private File System with…

1 year hace

JavaScript: download file with fetch

In this post you will learn how to download a file in the background using…

1 year hace

SQLite3 with vanilla JavaScript and OPFS – Hello world

In this post I will show you how to use SQLite3 directly in the web…

1 year hace

Python Thermal Printing: A Comprehensive Guide for Printing on Thermal Printers

In this tutorial, we'll explore how to effortlessly print receipts, invoices, and tickets on a…

1 year hace

Image printing on Thermal printer

When printing receipts on thermal printers (ESC POS) sometimes it is needed to print images…

1 year hace

Esta web usa cookies.