简体   繁体   English

node.js中的JSGI和`http.createServer()`是执行服务器端JavaScript Web应用程序的两种替代方法吗?

[英]Are JSGI and `http.createServer()` in node.js two alternative ways for executing a server side JavaScript web application?

I see that we can write a server side web application in JavaScript without framework, by using http.createServer() from https://medium.com/@saurabhkumar_4718/a-simple-nodejs-server-without-express-js-6773122d365f 我看到我们可以使用https://medium.com/@saurabhkumar_4718/a-simple-nodejs-server-without-express-js-6773122d365f中的 http.createServer()在不使用框架的情况下使用JavaScript编写服务器端Web应用程序

I also see from https://en.wikipedia.org/wiki/JSGI 我也从https://en.wikipedia.org/wiki/JSGI看到

JSGI, or JavaScript Gateway Interface, is an interface between web servers and JavaScript-based web applications and frameworks JSGI或JavaScript网关接口是Web服务器与基于JavaScript的Web应用程序和框架之间的接口

Are there two methods alternative to each other, both for executing a server side JavaScript web application? 是否存在两种彼此替代的方法,两种方法都可以执行服务器端JavaScript Web应用程序? Or are they used for different purposes, and can work together? 还是它们用于不同目的,并且可以一起工作?

Why do we need JSGI when we can achieve the same by creating a server by http.createServer() ? 当我们可以通过http.createServer()创建服务器来实现JSGI时,为什么需要JSGI?

as mentioned in the comment JSGI is old and very low-level interface between a HTTP server and JavaScript-based web applications . 如评论中所述, JSGIHTTP服务器和基于JavaScript的Web应用程序之间的接口,并且级别很低。 I personally have never came cross any node.js code that uses JSGI . 我个人从未遇到过使用JSGI任何node.js代码。 you can use http.createServer() to run your http server in nodejs but you then have to take care of a lot of things such as parsing the requests and responses. 您可以使用http.createServer()在nodejs中运行http服务器,但是随后您必须处理很多事情,例如解析请求和响应。 You also don't need JSGI when using http.createServer() 使用http.createServer()时,您也不需要JSGI

a better (more practical,modern and high-level) way to run web server on nodejs is to use express or koa . 在nodejs上运行Web服务器的更好(更实用,更现代,更高级)的方法是使用expresskoa

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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