What is the Client / Server model when using Electron (Atom Shell)?

I am trying to wrap my head around how Electron (formerly Atom Shell) works.

I come from a traditional MVC-style web application, where the browser invokes the action of the controller through the routing system, then the controller retrieves data from the storage (File system, Database ...) and displays a view that is sent back to the browser. Some actions may send JSON instead, because they are invoked through JavaScript / AJAX instead of the browser actually navigating to them.

I want to create this, but as a cross-platform desktop application. I know that Atom Shell combines both Chromium-Browser and Node.js / v8, but I'm not sure how they will communicate.

I suppose I could start a full web server (basically some Node.js HTTP Middleware, such as Express ), but this creates a network connection, (which can also disable firewalls) is one of the reasons why I want to create a desktop application - this is just to avoid starting a real server. In principle, as an MVP / MVVM pattern in a normal working application.

Can someone give me some starting points for what I'm trying to do? How will the browser speak with the node runtime (β€œClient”, what do they call it?), To say β€œHey, take my entry with ID 12345” and whether the client will return the rendered HTML or will only the browser drop JSON back and render it using JavaScript template engine?

+63
javascript electron
Jul 05 '14 at 5:12
source share
2 answers

The electron does not use Node.js as a web server, but simply as an environment for running JavaScript background code, this code can use node modules to access the system. At the same time, Chromium provides a user interface for the application, it displays regular web pages that run plain sandbox JavaScript. Both are built into the Electron executable, the first directly (Node.js can be created as a static library), and the second via libchromiumcontent . In a way, Node.js is part of the application controller, while Chromium is a view.

As a rule, the concept used for web pages refers to single-page applications : a web page is a single application window and, as such, remains as long as this window is visible (often throughout the life of the application). Whenever he needs to display something else, he requests data from the background code running in Node.js, just like AJAX applications request data from the server. The page itself does not reload, usually the JavaScript template will be used to update the content.

However, in fact, the relationship between the server and the client is not really connected, and communication can really go in both directions. Both parties can use the ipc module to send messages to each other ( main process , renderer ). These messages can have any arguments associated with them, they do not have to be encoded explicitly (as a rule, this is implemented using JSON for internal parameter encoding, I did not check if this is the case with Electron). Internally, this messaging is implemented using libuv mechanisms.

+61
Jul 07 '14 at 20:12
source share

We have implemented a fully functional nodejs server and angular user interface with sqlite3, sequestered ORM using

*. https://github.com/theallmightyjohnmanning/electron-express

Some of the projects have helped us:

+3
Dec 26 '16 at 5:09
source share



All Articles