electronify-server
is a lightweight tool which starts a local web server and opens a url in an Electron shell.
npm install --save electronify-server
When the Electron app loads, electronify-server
will start a child process with the command you gave it in the configuration. This command is assumed to be a web server (but it doesn't have to be). If the child process was started successfully, the window will open and load the url to your server.
There are a couple examples included in the repo. In order to run the examples, you need to have electron installed. If you do not have it installed, perhaps the simplest way is to use electron-prebuilt
like so:
npm install -g electron-prebuilt
To run the examples, simply go into each example folder and run:
electron .
The static
example has a dependency that will need to be installed first via:
npm install
var electronify = require('electronify-server');
electronify({
url: 'https://google.com',
noServer: true
});
var electronify = require('electronify-server');
electronify({
command: 'python -m SimpleHTTPServer',
url: 'http://127.0.0.1:8000',
debug: true,
window: {height: 768, width: 1024},
ready: function(app){
// application event listeners could be added here
},
preLoad: function(app, window){
// window event listeners could be added here
},
postLoad: function(app, window){
// url finished loading
},
showDevTools: false
}).on('child-started', function(child) {
// child process has started
console.log('PID: ' + child.pid);
// setup logging on child process
child.stdout.on('data', console.log);
child.stderr.on('data', console.log);
}).on('child-closed', function(app, stderr, stdout) {
// the child process has finished
}).on('child-error', function(err, app) {
// close electron if the child crashes
app.quit();
});
url [String]
: URL to load after child process startscommand [String]
: command to start child processoptions [Object]
: options for execdebug [Boolean]
: enables debug outputnoServer [Boolean]
: allows urls to load without starting a child processshowDevTools [Boolean]
: shows dev tools on startupwindow [Object]
: BrowserWindow configurationready [Function]
: called when the application is readyapp [Object]
: Electron application
preLoad [Function]
: called after the window is created but before the url is loadedapp [Object]
: Electron applicationwindow [Object]
: Electron BrowserWindow
postLoad [Function]
: called after the url has finished loadingapp [Object]
: Electron applicationwindow [Object]
: Electron BrowserWindow
electronify
also returns an EventEmitter which emits several events for the child process. This allows you to do additional work when the child process starts, exits or fails unexpectantly.
child-started
: Emitted immediately on successful start of child processprocess
: The child process that was started
child-closed
: Emitted when the child process exits gracefully.app
: Electron applicationstderr
: Standard error of child processstdout
: Standard output of child process
child-error
: Emitted when the child process fails.err
: Error returned from executing child process.app
: Electron application
error
: Configuration errorerr
: Configuration errorapp
: Electron application