简体   繁体   English

我可以使用 express.js 创建 web api 并且没有安装 node.js 吗?

[英]Can I create web api using express.js and not have node.js installed?

I am currently in the process of creating a portfolio website for myself but due to hosting restrictions, I cannot make use of Node.js.我目前正在为自己创建一个投资组合网站,但由于托管限制,我无法使用 Node.js。

I know Angular can run on any web server, but is it possible to make use of Express.js to create web api's with relying on Node.js to run these web api's using Express.js? I know Angular can run on any web server, but is it possible to make use of Express.js to create web api's with relying on Node.js to run these web api's using Express.js?

If not, is there an alternative solution to create web api's that I can call using Angular and later for my mobile version of my website?如果没有,是否有替代解决方案来创建 web api,我可以使用 Angular 及更高版本为我的网站的移动版本调用?

Please note that my shared hosting runs using cPanel.请注意,我的共享主机使用 cPanel 运行。

As per definition Express.js, or simply Express, is a web application framework for Node.js so you can't do that.根据定义,Express.js 或简称为 Express,是 Node.js 的 web 应用程序框架,因此您不能这样做。 Alternatives would be to use a different backend language.替代方案是使用不同的后端语言。 That also depends if your server supports them, for example, you can go with .NET CORE这也取决于您的服务器是否支持它们,例如,您可以使用 go 和.NET CORE

You cannot use Express without NodeJS by definition so you have to deploy your backend somewhere else in you want to use it.根据定义,您不能在没有 NodeJS 的情况下使用 Express,因此您必须将后端部署在您想使用它的其他地方。

I suggest giving a look Firebase : you could write your backend using http cloud functions in express without paying anything until a reasonable amount of traffic (after that, is pretty cheap).我建议看一下Firebase :您可以使用http 云函数快速编写后端,而无需支付任何费用,直到达到合理的流量(之后,非常便宜)。 You could also get rid of cPanel and deploy your frontend there via Firebase hosting .您还可以摆脱 cPanel 并通过Firebase 托管在那里部署您的前端。

Maybe you can try to build at first a web application with express.也许您可以先尝试使用 express 构建 web 应用程序。 Of course you can create a web app without express if you need it.当然,如果你需要的话,你可以创建一个没有快递的 web 应用程序。 With express and Node.js I created a MySQL REST API.使用 express 和 Node.js 我创建了一个 MySQL REST ZDB974238714CA8DE634A7CE1D083A14F。 With HTML and Ajax you can fetch the Data from the API.使用 HTML 和 Ajax,您可以从 API 获取数据。 So you can create two applications.因此,您可以创建两个应用程序。 One application where you need to run Node.js because it`s much easier to create a REST API with express.您需要运行 Node.js 的一个应用程序,因为使用 express 创建 REST API 要容易得多。 The second one is fully without Node.js.第二个完全没有 Node.js。

Maybe there are better solutions, but inside each Web Application you can than but you can then access this API in any web application using jQuery.也许有更好的解决方案,但在每个 Web 应用程序中,您可以使用 API 在任何 web 应用程序中访问此 API,使用 ZC67A5EC9705EB7AC2C984033E06189DZ 应用程序。 It doesn't matter if it is written with PHP, ASP.Net Core, Java EE / EE4J.用 PHP、ASP.Net Core、Java EE / EE4J 写都没关系。 You can also access this API in Ruby, Angular, React, Vue etc. using an AJAX request.您还可以使用 ZA34A6659BCEAE779F2818 请求在 Ruby、Angular、React、Vue 等中访问此 API。

In some scenarios you can't start Node.js as a server because an application is already running on apache2 or nginx.在某些情况下,您无法将 Node.js 作为服务器启动,因为应用程序已经在 apache2 或 nginx 上运行。 There this would be a workaround to use something like this.这将是一种解决方法来使用这样的东西。 For example, one could also integrate applications with HTML+JS in a CMS system that accesses other database tables and thus extend such a system without an iframe.例如,还可以在访问其他数据库表的 CMS 系统中将应用程序与 HTML+JS 集成,从而在没有 iframe 的情况下扩展这样的系统。

So can be helpful for few scenarios.因此对少数情况会有所帮助。 Now just doesn't get around the actual goal of doing without Node.js completely or even express.现在只是没有完全或什至表达没有 Node.js 的实际目标。 But why are there REST APIs?但是为什么会有 REST API? So that you can query the data and incorporate it somewhere else.这样您就可以查询数据并将其合并到其他地方。 Otherwise you would have to build a REST API with another technology.否则,您将不得不使用另一种技术构建 REST API。 Especially in the example of accessing MySQL with JavaScript, this would not be quickly feasible.尤其是在使用 JavaScript 访问 MySQL 的示例中,这不会很快可行。

If you are looking for a similar solution to separate the web app and the REST API, but you don't need Node.js, then you should really build a REST API with.Net Core or with another technology, depending on what is possible and installed on your server. If you are looking for a similar solution to separate the web app and the REST API, but you don't need Node.js, then you should really build a REST API with.Net Core or with another technology, depending on what is possible and installed在您的服务器上。 It could be Java or PHP behind it or Ruby.后面可能是 Java 或 PHP 或 Ruby。

The API that provides the REST access does not have to be written in JavaScript.提供 REST 访问的 API 不必写入 JavaScript。 You only need to be able to access it with JavaScript.您只需要能够通过 JavaScript 访问它。 So you can use many different approaches to access JSON data.因此,您可以使用许多不同的方法来访问 JSON 数据。 I hope that in the short time with my bad English I have explained the basic idea, how to proceed stylistically and where advantages exist in REST interfaces.我希望在短时间内用我糟糕的英语解释基本概念,如何在风格上进行以及 REST 接口存在哪些优势。

With this, it should be self-explanatory that you don't have to use NodeJS and Express, but with JavaScript it's a pleasant solution.有了这个,你不必使用 NodeJS 和 Express 应该是不言自明的,但是使用 JavaScript 这是一个令人愉快的解决方案。 Only you have to ask yourself if a JavaScript application has to provide this interface at all or if in the end only a JavaScript application has to access this interface.您只需要问自己,JavaScript 应用程序是否必须提供此接口,或者最终是否只有 JavaScript 应用程序必须访问此接口。 Very big difference.非常大的区别。

For backend rest api you can use golang with gorilla framework.对于后端 rest api,您可以将 golang 与 gorilla 框架一起使用。 Golang simple keyword and easy to learn.best important point is performance. Golang 关键字简单易学。最重要的一点是性能。 If your server support golang you can use golang for backend..如果你的服务器支持 golang,你可以使用 golang 作为后端。

ExpressJS is NodeJS framework so it's impossible to create an API without NodeJS. ExpressJS 是 NodeJS 框架,因此无法在没有 NodeJS 的情况下创建 API。 Angular is front-end framework so you can host it on web hosting server. Angular 是前端框架,因此您可以将其托管在 web 托管服务器上。 If you need to create back-end APIs, you can use other clouding host servers that support NodeJS.如果需要创建后端 API,可以使用其他支持 NodeJS 的云主机服务器。

It's fairly simple to build this with just the net/http package.仅使用 net/http package 来构建它是相当简单的。 Set up a router that handles various commands and deal with the response accordingly.设置一个处理各种命令并相应处理响应的路由器。

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

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