How to Remove Port Number From URL of Node JS Application?

Source: Internet
Author: User
Keywords node js application node js web application application node js
I am new to node js. In my application url, the port number must be specified like localhost:3000/a.
How to remove the port number from the URL. I tried setting the port number to 80. But it's useless to me.
Even if I set the port to 8080, I must specify the port number 8080 to work. If not specified, a 404 will be raised, just like the behavior of a simple server.

If you want to use port 80, you should run the application with root/admin rights and make sure that no other server is running on this port. In fact, most people will deploy a reverse proxy to handle static content and route the remaining requests to the node.js application. nginx is usually used for this. You will find plenty of resources to explain how to do this.

Node js application calls the same function multiple times-stack overflow

Okay, so I have developed an application that can run 24/7. If I write this, I only have one question:

 setInterval(getWCProducts  , 1000*intervall); 

    function getWCProducts(){
      //code
    }

    function test(){
        console.log("Hello!")
    }
    test() 

It will call the test again and again. It will display "Hello!" almost every second. Why is the application like this? Obviously, the "real" function is not just about printing "hello!" The real function is the "setting function", which can prepare the application before it starts to cycle, and I can't let it run the setting function again and again.

The cycle only starts after completing the settings.
function main() {
     console.log("doing my main thing");
}

function setup() {
    console.log("doing my setup stuff ");
    setInterval(main, 1000);
}

What I want to point out is that for most real-world setInterval applications, you don’t want to start an interval call function separately, but really want to start an interval call each function after the last call. If this is the case, the modified code will look like this:

function main() {
     console.log("doing my main thing");
     setTimeout(main, 1000);
}

function setup() {
    console.log("doing my setup stuff ");
    main();
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.