I had used electron to create a desktop app, but I have some problem let me show my code first
my server.js
'use strict';
var loopback = require('loopback');
var boot = require('loopback-boot');
var path = require('path');
var bodyParser = require('body-parser');
var app = module.exports = loopback();
// configure view handler
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
app.use(loopback.token());
console.log("hi")
app.start = function() {
// start the web server
console.log("hi1")
return app.listen(function() {
app.emit('started');
var baseUrl = app.get('url').replace(/\/$/, '');
console.log('Web server listening at: %s', baseUrl);
if (app.get('loopback-component-explorer')) {
var explorerPath = app.get('loopback-component-explorer').mountPath;
console.log('Browse your REST API at %s%s', baseUrl, explorerPath);
}
});
};
boot(app, __dirname, function(err) {
if (err) throw err;
// start the server if `$ node server.js`
if (require.main === module)
console.log("hi2")
app.start();
});
here is my index.js of electron
'use strict';
const electron = require('electron');
const {app, BrowserWindow,crashReporter} = electron;
require(__dirname+'/server/server.js');
let mainWindow;
function onClosed() {
mainWindow = null;
}
function createMainWindow() {
const win = new BrowserWindow({
width: 600,
height: 400
});
win.loadURL('http://localhost:3000/');
win.maximize();
win.on('closed', onClosed);
return win;
}
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate-with-no-open-windows', () => {
if (!mainWindow) {
mainWindow = createMainWindow();
}
});
app.on('ready', () => {
mainWindow = createMainWindow();
});
and in my package json(where my application start i mean before electron. package json required to run server) i modify it to run electron app
{
"name": "login",
"version": "0.1.0",
"productName": "login",
"main":"index.js",
"engines": {
"node": ">=4"
},
"electronVersion": "^3.0.2",
"scripts": {
"start": "electron .",
"build": "electron-packager . $npm_package_productName --out=dist --ignore='^/dist$' --prune --asar --all --version=$npm_package_electronVersion",
"posttest": "npm run lint && nsp check"
},
"keywords": [
"electron-app"
],
"dependencies": {
// required dependencies to run project
"electron-debug": "^2.0.0",
},
"devDependencies": {
"electron": "^3.0.2",
"electron-winstaller": "^2.7.0",
},
}
now my problem is that it work correctly if i do console.log("hii") console.log("hi1") and console.log("hi2") in server.js example provide above and if i remove all 3 console.log then electron app does not start app can any body tell me what is this issue