Using the CloudRail Node.js SDK with Electron
Consequently it is not hard to use the CloudRail SI Node.js SDK in Electron based applications and we will discuss how it’s done. We will create a small app that gets a user’s authorization to access their Dropbox account and then presents information about available space. From there on it is easily extended to work with all the other functionalities CloudRail SI provides.
How it works
The package.json shoud look like this:
This is mostly the general information a Node.js application should have. In addition, we note in particular the main entry which references our background logic file, a startup shortcut and the dependency to the CloudRail SI library.
The main.js has the following content:
This file will initialize our app by creating a new View and loading the contents of the index.html into it.
The index.html has some simple HTML:
Most importantly it defines two buttons to click, a pane to display text and references the renderer.js file.
This file is where the interesting stuff happens. The CloudRail SI library is imported and the Dropbox service initialized. The use of the method getElectronAuthenticator is the main distinction point from a non-Electron node.js app, it makes sure authentication is neatly integrated into the View. The rest of the code essentially registers click listeners on the two buttons which trigger the interaction with the Dropbox service. The code using the localStorage, saveAsString and loadAsString makes sure that a user does not have to reauthenticate after restarting the app since credentials are persisted.
That’s it, you can execute the app with the usual npm install && npm start and have it running. That’s what it should look like:
As you can see it’s really easy to use CloudRail with electron apps to enrich them with a plentitude of useful API integrations. Have a look at the CloudRail SI Node.js SDK’s documentation to learn about all the other methods and services you can use.