Electron - Processing Input Electron - Processing Input node.js node.js

Electron - Processing Input


With Electron, node.js is not acting as a webserver with routes like it would be in a typical web application scenario. Instead of sending requests to routes, you would create a single page application using a javascript framework like Angular, React, Knockout, etc. At that point, you no longer need to handle routing. You would tie your 'Submit' click event to a javascript function directly within the page, and process the input from there.

You can do everything from the page's javascript context that you can do from the node.js main process context. For instance, if you needed to access the file system from your page, you would use the Remote module to gain access to the node.js native APIs.

For example:

// Gain access to the node.js file system apifunction useNodeApi() {  const remote = require('electron').remote;  const fs = remote.require('fs');  fs.writeFile('test.txt', 'Hello, I was written by the renderer process!');}

I've rarely come across a situation where I needed to pass control back to the main process to accomplish something. Once the BrowserWindow launches, anything you could ever need to do could be done from the renderer process. This pretty much eliminates the need to do things like submit form posts via http.