Question

How can I set a default Port number?

I am not using nginx or apache on my application. When I try to get to my domain “mfall33.tk” it “refuses to connect” although I can access my app through my ip address. I think that becase I cant specify my IP Address with my app that the domain can’t access it, is there anyway I could go about specifying it?

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Without more information about you application, it’s hard to give you a through answer to your questions. Generally, the port that an application listens on is defined by the application itself in some way. That could be an environmental variable or a run time configuration flag.

Take this simple Express app example:

#!/usr/bin/env node
var debug = require('debug')('my-application');
var app = require('../app');

app.set('port', process.env.PORT || 3000);

var server = app.listen(app.get('port'), function() {
  debug('Express server listening on port ' + server.address().port);
});

It defaults to using port 3000 unless the PORT environment variable is set to a different value.

Assuming you have an A record for mfall33.tk pointing to the IP address of your server, to reach the app by visiting the domain it must be listing on port 80 for HTTP or port 443 for HTTPS. This is one of the reasons people put Nginx or Apache in front of their app. The web server can listen to both, redirect one to the other if desired, and proxy the application. So even if you are able to configure the port for your application, it’s still likely worthwhile to put a revers proxy in front of it. Check out this tutorial for an example: