I want to create a cross-platform app in Desktop and Web Browser with electron and each of these have a separate database, SqLite for Desktop and MySQL for Web. is logically possible to code once for both of them?
Asked
Active
Viewed 212 times
1 Answers
1
You should be able to the functionality that is specific to Electron or the Browser by checking if Node-specific globals are available. They will be available in Electron, but they won't be in a traditional browser application.
You could do this with something along the lines of:
var isElectron = false;
if (typeof 'process' !== 'undefined') {
isElectron = true;
}

Steve Kinney
- 756
- 5
- 5
-
Thanks @Steve ,I mean, can i reuse Electron code blocks in browser side (http) or I have to writing browser side again? – myvahid May 07 '16 at 06:43
-
@myvahid You can definitely reuse code on the browser-side. In Electron, you can use `require` to require a file or `electron.remote.require` if you want to pull it code but have it execute from the main process. – Steve Kinney May 07 '16 at 12:48