How does a Node.js “server” compare with Nginx or Apache servers?

后端 未结 3 1223
心在旅途
心在旅途 2021-01-29 17:37

I have been studying Node.js recently and came across some material on writing simple Node.js based servers. For example, the following.

var express = require(&qu         


        
3条回答
  •  没有蜡笔的小新
    2021-01-29 18:34

    NodeJs creates its own server. As you can see, terminology is quite clear:

    http.createServer(app).listen(3000);
    

    Create a server and listen for http requests on port 3000.

    We used nginx in one of our project, but it was more like a loadbalancer for multiple nodejs instances.

    Lets say you have two nodejs instances running on port 3000 and 3001, Now you can still use nginx as a server to listen your actual http calls on port 80, and may want to redirect your request to nodejs server or maybe some other server, more like a loadbalancer. So you can still use whatever nginx provides with nodejs.

    A good question already asked here.

提交回复
热议问题