我应该在电子应用程序中使用什么作为后端?

What should I use as backend in electron application?(我应该在电子应用程序中使用什么作为后端?)
本文介绍了我应该在电子应用程序中使用什么作为后端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我知道我可以使用 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.

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

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
Ordinals in words javascript(javascript中的序数)
getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)