Angular + Express.js app in Electron doesn't starts

Asked
Active3 hr before
Viewed126 times

6 Answers

startsdoesnexpressangularelectron
90%

This should create a new file src/app/images,service

Example_snippet/controller/utility/_starts.js/ npm install -g @angular/cli@7.. . .
npm install - g @angular / cli @7 .3 .6
load more v
88%

Before we can start working on our electron angular app, we need to set up some stuff first,,For now, we will leave the angular app as it is and focus on starting it inside of electron

Example_snippet/controller/utility/_starts.js/ npm install -g @angular/cli. . .
npm install - g @angular / cli
load more v
72%

If I load up HTML content via an Express server embedded in the Electron app, then does the HTML source have access to node,js functionality? I just started experimenting with Electron and my understanding is that loadUrl("file://

Example_snippet/controller/utility/_starts.js/ const express = require('./exp. . .
const express = require('./express'); //your express app

app.on('ready', function() {
   express();
   mainWindow = new BrowserWindow({
      width: 1280,
      height: 720,
      autoHideMenuBar: true,
      useContentSize: true,
      resizable: false,
   });
   mainWindow.loadURL('http://localhost:5000/');
   mainWindow.focus();

});
Step 2 continued with app.set('views', '/client/view. . .
app.set('views', '/client/views');
app.use(express.static(/client/dist / static));
Step 3 continued with app.set('views', __dirname + '. . .
app.set('views', __dirname + '/client/views');
app.use(express.static(__dirname + '/client/dist/static'));
load more v
65%

To run our app, we add the run script, which invokes Electron in our package directory:,The file src/index,html is the entry point for our Angular application

Example_snippet/controller/utility/_doesn.js/ const {app, BrowserWindow}. . .
    const {
       app,
       BrowserWindow
    } = require('electron')
    const path = require('path')
    const url = require('url')
    // Create the browser window.
    win = new BrowserWindow({
       width: 800,
       height: 600
    })
    // and load the index.html of the app.
    win.loadURL(url.format({
       pathname: path.join(__dirname, 'index.html'),
       protocol: 'file:',
       slashes: true
    }))
load more v
75%

For this Electron tutorial, I am going to be using an example repo I have created in that getting started blog I linked above, With that in mind, you will need to have the proper node and npm packages installed for any Angular application

Example_snippet/controller/utility/_doesn.js/ const { app, BrowserWindow } =. . .
const {
   app,
   BrowserWindow
} = require('electron')
const path = require('path')
const url = require('url')
let win;

function isDev() {
   return process.mainModule.filename.indexOf('app.asar') === -1;
};

function createWindow() {
   win = new BrowserWindow({
      width: 800,
      height: 600
   })
   win.loadURL(url.format({
      pathname: path.join(__dirname, '../dist/index.html'),
      protocol: 'file',
      slashes: true
   }));
   if (isDev()) {
      win.webContents.openDevTools()
   }
   win.on('closed', () => {
      win = null
   })
}
app.on('ready', createWindow)
app.on('window-all-closed', () => {
   if (process.platform !== 'darwin') {
      app.quit()
   }
})
app.on('activate', () => {
   if (win === null) {
      createWindow()
   }
})
load more v
40%

The server starts successfully but the electron app doesn't rendered,, Meta Stack Overflow , Outdated Answers: accepted answer is now unpinned on Stack Overflow , Stack Overflow Public questions & answers

Example_snippet/controller/utility/_doesn.js/ const { app, BrowserWindow } =. . .
const {
   app,
   BrowserWindow
} = require('electron')

const path = require('path');

function createWindow() {
   win2 = new BrowserWindow({
      width: 800,
      height: 600
   })

   win2.loadURL(
      path.join('file://', __dirname, '/index.html')
   );
}

app.on('ready', createWindow)
load more v