Can we say node.js is a web server?

天大地大妈咪最大 提交于 2019-12-03 00:12:26

问题


I found that I am confusing between web framework and web server.

Apache is a web server.

Tornado is a web server written in Python.

Nginx is a web server written in C

Zend is a web framework in php

Flask/Bottle is a web framework in Python

RoR is a web framework written in Ruby

Express is a web framework written in JS under Node.JS

Can we say node.js is a web server??? I am so confused between web server/ framework.

If somehow node.js is kind of webserver, not webframework (Express does), why do we need to put the whole node.js on top of Nginx server in useful practice?? Question on SO

Who can help???

Kit


回答1:


Web server

Web server can refer to either the hardware (the computer) or the software (the computer application) that helps to deliver content that can be accessed through the Internet.1

The primary function of a web server is to deliver web pages on the request to clients. This means delivery of HTML documents and any additional content that may be included by a document, such as images, style sheets and scripts.

A web server is the basic to delivering requests/pagess to the clients/user on the internet

Web framework

A web application framework is a software framework that is designed to support the development of dynamic websites, web applications and web services. The framework aims to alleviate the overhead associated with common activities performed in Web development. For example, many frameworks provide libraries for database access, templating frameworks and session management, and they often promote code reuse.

A web framework uses a webserver to deliver the requests to client, but it is not the web server.

Node.js

Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.

But then again you can also create CLI apps so I think you should see it more as a platform to write javascript programs to run on your server(computer) using Javascript programming language instead of just in the browser as in the beginning. I think you could see it as Javascript++ ??

You can also write web server with node.js as you can see on the front page of node.js. In the beginning Ryan said you could put Nginx in front of node.js because of the stabilty of the project. The project was and still is pretty young. Nginx is a proven web server that will keep on running while node.js can crash. Then again a lot of user just use node.js for that.




回答2:


I would say Node.js is a Runtime Environment or a Runtime Engine.

Probably the best definition I have found so far comes from an article by Rob Gravelle entitled "An Intro to Node.js":

Node.js is part runtime environment and part library for building network applications using server-side JavaScript. It uses Chrome's JavaScript runtime engine to execute JS code directly without the need for the browser sandbox.

Also the PCMAG.COM Encyclopedia provides the following definition of "runtime engine":

Software that certain applications depend on to run in the computer. The runtime engine must be running in the computer in order for the application to execute. It provides common routines and functions that the applications require, and it typically converts the program, which is in an interim, intermediate language, into machine language.

Also the Wikipedia article entitled "Run-time system" declares:

A run-time system (also called runtime system, runtime environment, or just runtime) implements the basic behavior of a computer language, whether the language is a compiled language, interpreted language, embedded domain-specific language, or is invoked via an API as is pthreads.

... A run-time system may implement behavior of tasks such as drawing text on the screen or making an Internet connection. It also typically acts as an abstraction layer that hides the complexity or variations in the services offered by the operating system.

Well, are there any runtime environments (or even software platforms) like Node.js out there? I guess JRE is a good example of such an environment. Node.js and JRE - they have many in common. They all have (a kind of) virtual machine, a class library and a framework to implement many types of applications, including CLI ones.

So, getting back to your question, can we say that Node.js is a web server? Let's change "Node.js" for "JRE" and answer if JRE is a web server. The answer is no.

All that we can say is that Node.js is a runtime environment which one may use to implement a web server. Well, that's my opinion.




回答3:


Saying node is a webserver is like saying javacript can only run inside a browser, you can say that but it can also do a lot of other things.

NodeJS

  1. [Javascript runtime enviroment(Chrome v8 engine) + Node Library/APIs]
  2. Can create a web server, can also be described as a Application server

Express

  1. Web framework (uses nodejs's webserver to serve files)

Nginx

  1. Web server

In production most people use Nginx in front of node server as a proxy server to serve static files and other various elements like caching, routing etc.




回答4:


I would classify node.js as a server framework, with packages available that can make use of it as an HTTP server, or a WebSocket server, or your own custom protocol, etc.

The reason you might put nginx in front of your node.js server is for HTTP load balancing and reverse proxying across several machines running your server application.




回答5:


Web server is something that serves its clients through internet over protocols and Web Framework is something like which we call as compiler. It consists of all the required libraries, syntax rules, etc.

And node.js is a framework!!




回答6:


I think the problem is that the terminology of "web server" or "web application server" is dominated by the JEE world, and products, that are not as modularized as today's Javascript world of frameworks, which in turn can be combined more or less freely.

I see no reason why a technology, that can serve complex applications over the web, should not be called a web server, or web application server!

If you combine, let's say Nuxt as a frontend, with Feathers as a backend - you'll have a backend serving a REST API and a server-side rendered UI!

Of course, you could (mis)use that to serve static content - then I'd call it a web server, or you could use it to make and serve a full application - then I'd call it a web application server.

It's the combined features or qualities that sum up to serve a purpose - right? - Features like stability, scalability and such are IMHO something that will be added to those technologies, over time. For now, they're pretty new still.




回答7:


No it's a runtime environment... so it is not a web server yet it does not need one to run. So probably this is why it could be confusing. It can run standalone without needing any webserver because it is a runtime itself but again it is not a webserver.




回答8:


How I feel your pain !

Like many, I found it hard to get to the essence of Node.js because most people only write/talk about the part of Node that they find useful - and the part they find interesting is usually a secondary benefit of Node rather than its primary purpose. I must say that I think it's mad for people to say that Node is just a JavaScript runtime. Node's use of JavaScript - and its selection of the V8 runtime - are simply means to an end, the best tools for the problem that Node's developers wanted to solve.

Node's primary purpose was to make the management of user events in a web app more efficient. So Node is overwhelmingly used on the back end of a web app. Event management demands that something is listening at the server machine for these events. So a http server must be set up to route each event to its appropriate handler script. Node uses JavaScript for event handling because JavaScript has callback functions: this allows one task to be suspended until the result of a dependent task is returned. Not many other languages have this feature and those that do may not have as efficient an interpreter as Google's V8 runtime. Most web developers know JavaScript so there's no additional language learning with Node. What's more, having callback functions allows the putting of all user tasks on a single thread without having explicit blocking applied to tasks demanding access to the database or file system. And this is what leads to the superior executional efficiency of Node under heavy concurrent use - which was the primary purpose for its development.

To help Node users quickly write back end code, Node's developers also organized the NPM (Node Package Manager) repositary: this is an open source, user-driven set of script packages for various standard and custom functions. All Node projects allow importation of NPM packages into a project via the established npm install command.

User requests handled via Node will be things like register/login/logout/form field validation and various database queries needed by the web app will be sent to the Node port. Other types of user request, e.g. to display another webpage, download CSS/JS/images, etc, could be sent to Node also. But these are not normally be sent to the Node port but will continue to be sent by the browser to the default port(s) on the server machine where the web server will handle them.

So, in practice, Node is normally a server but one that only replaces some of the functions of the web server program. Other uses of Node simply exploit one or other of its features, e.g. the V8 engine. But these are really just by-product uses of Node.



来源:https://stackoverflow.com/questions/9462356/can-we-say-node-js-is-a-web-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!