简体   繁体   中英

Why asp.net needs IIS(Internet Information Services) to run web server? How this works in nodejs?

If a web application is developed in Asp.net , IIS is needed to run a webserver.

How these two(Asp.net and IIS) works together ? Do IIS takes the build files and runs the server?

How expressjs (A frame work of nodejs) run web server since it isn't using any other software?

I can explain the node.js side of things and hopefully someone else can come along and explain the IIS/ASP.net side of things.

Node.js is a generic Javascript run-time environment. You can build all sorts of apps in it, even applications that have nothing at all to do with a web server.

It so happens that one of the built-in libraries in node.js is an http/https server. So, if you want to build a node.js-driven web server, you just grab the http server object, create a server, start it and program away on request handling.

Express is a web framework that is built on top of the node.js http/https server objects. It uses the built in server and provides a framework around that for defining request handlers, setting up routing and middleware and the middleware API is supports enables all sorts of 3rd party libraries for doing a wide variety of web-server-type things such as authentication, encryption, compression, uploads, downloads, image handling, audio handling, video handling, etc...

What set node.js apart from a number of other web-server frameworks is that node.js didn't start out saying I'm only a tool for doing web server stuff. It started out as a generic programming environment that happened to have a pretty good web server built-in as one of the tools one could use. And, it only takes a few lines of code to create and start your own web server using the built-in support. I would hazard a guess that building web-server apps is perhaps the most popular thing to do with node.js, but certainly not the only thing.

For example, I have a node.js script I wrote that does nightly housecleaning on my disk drive. It removes certain types of files from my temp directory. It helps manage backup files (keeping only the last 10 backups of my Adobe Lightroom catalog). This use of node.js has absolutely nothing to do with a web server. It's just a Javascript run-time environment that I happen to use the file system access libraries in it to do a bunch of file management.

For example, here's code to start a basic web server in plain node.js:

const http = require('http');
const server = http.createServer(function(req, res) {
    console.log("got a request from", req.url);
    res.end("Hi");
});

// start web server on port 3000
server.listen(3000);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM