在电子应用中我应该使用什么作为后端? [英] What should I use as backend in electron application?

查看:78
本文介绍了在电子应用中我应该使用什么作为后端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以使用HTML CSS JavaScript或任何其他前端框架来设计UI。
我什至知道我可以连接到任何远程API。
如果我想要一个带有数据库的独立应用程序怎么办。我应该如何连接到数据库?我应该在哪里编写应用程序逻辑?
我感觉电子中缺少一部分,我是否应该使用像Express这样的节点JS Web框架?
还是我应该在不使用任何框架的情况下在纯节点JS中编写所有程序逻辑?
如果可能的话,编写电子应用程序的最佳方法是什么?

I understand I can design the UI with HTML CSS JavaScript or any other frontend framework. I even understand that I can connect to any remote API. what if I want a standalone application with database. How should I connect to the database ? where should I write my application logic? I feel like there is a missing part in electron do I supposed to use a node JS web Framework like Express? or I should write all the program logics in pure node JS without using any framework? What is the best approach to write electron applications if possible please point me any working example.

推荐答案

虽然我们在Web应用程序中习惯的客户端/服务器(前端/后端)模型是一个好主意(关注点分离),但是

While the client/server (frontend/backend) model we've got used to in web applications is a good idea (separation of concerns), it's not the only way to do things when the client and the server are on the same machine.

Electron是在Node.js之上构建的。因此,您可以使用常规的npm模块来连接到您要使用的任何数据库系统,并取消使用框架。例如,如果您愿意,可以编写代码从数据库中将数据直接获取到 onclick 事件处理程序中。

Electron is built on top of Node.js. So you can use the usual npm modules in order to connect to whatever database system you want to use and do away with frameworks. For example you can write code to fetch data from the database right into your onclick event handler if you desire so.

话虽如此,如果您不小心,很可能会发现自己无法处理大量的意大利面条代码。因此,即使您不希望使用整个客户端/服务器系统,也建议使用某种结构。

Having said that, odds are you will find yourself dealing with an unmanageable bunch of spaghetti code if you're not careful. So, some kind of structure is recommended even if you don't want an entire client/server system.

此外,您的客户端您的服务器不必通过HTTP进行通信。该接口可以仅仅是普通的函数(和/或方法)调用。 Electron还具有消息传递系统(例如: https://electronjs.org/docs/api/ ipc-main

Also, your "client" and your "server" don't have to communicate through HTTP. The interface can be just plain function (and/or method) calls. Electron also has a message passing system (for example: https://electronjs.org/docs/api/ipc-main that you may use.

这篇关于在电子应用中我应该使用什么作为后端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆