D
D
Denoro552018-09-22 16:10:26
Node.js
Denoro55, 2018-09-22 16:10:26

How to correctly set the port on the hosting if you run the server on Node.js?

How to correctly set the port on the hosting if you run the server on Node.js?

var http = require('http');
var app = http.createServer(function(req,res){
  res.writeHead(200);
  res.write('Hello Denis');
  setTimeout(function(){
    res.write('Hello Timeout');
    res.end();
  },3000)
}).listen(8080);

Let's say I'm testing a server on a localhost on any port (8080 in this example), but if I install and run on a hosting port, should the port be the name of the domain? If the domain is called nodejs.ru, for example, what port should I write? Or is something else needed?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Kirill Kudryavtsev, 2018-09-22
@Deissh

It is better to use nginx as a proxy pass.
Not a bad article

A
Alexey, 2018-09-22
@Softovick

Strange questions for a web application writer :)
Firstly, if this is a website, then port 80 for http and 443 for https (with encryption and certificates) is considered by default.
Secondly, it strongly depends on what kind of site it is. If it contains a lot of static files, such as images, files, or it is SP, that is, just html is given, then it is strongly recommended to use Nginx as a proxy. In other cases, it is not necessary, but still recommended. That is, Nginx is launched on ports 80/443, and in the virtual host configuration, a proxy is assigned to the port on which the Node.JS application is running. You determine which port it is, the main thing is that it does not coincide with reserved system ports and ports occupied by other applications. In this case, the more productive Nginx bears the main load of content delivery, and your application generates dynamic content. It is also desirable that the port respond only locally on the server, then there will be fewer problems.
Thirdly, if this is still not a website (for example, a REST API service) or not quite a website (say, SPA on html and backend on Node.JS, some tasks are performed, well, or other options), then the port can be absolutely anything on your taste. The main thing is that it does not intersect with others, since usually only one application can hang on one port.
Addendum: Some use Docker or a more modern version of CoreOS. in this case, which port your application virtually uses, you specify in the settings. Accordingly, you can, for example, run several containers with different applications on different ports, linking them to each other if necessary (the same Nginx, for example, and a proxy to the container address with your application).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question