title: How to start node server locally in electron app
body: <p>I'm running a NG4-Electron application and now I want to start a local node js server (Express) when the electron app starts. I have a local folder named as <code>local_server</code> at the root of the application which contains the <code>node server.js</code>. Below is my <code>package.json</code>. I'm relatively new and not being able to understand how to start the server. </p>
  
  <pre><code>{
    "name": "demo_app",
    "version": "0.0.1",
    "description": "",
    "author": {
      "name": "Subbu"
    },
    "keywords": [
      "angular",
      "electron",
      "typescript",
      "sass"
    ],
    "main": "main.js",
    "private": true,
    "scripts": {
      "ng": "ng",
      "lint": "ng lint",
      "start": "npm-run-all --parallel webpack:watch electron:serve",
      "webpack:watch": "webpack --watch",
      "start:web": "webpack-dev-server --content-base . --port 4200 --inline",
      "build:electron:main": "tsc main.ts --outDir dist &amp;&amp; copyfiles package.json dist &amp;&amp; cd dist &amp;&amp; npm install --prod &amp;&amp; cd .. &amp;&amp; copyfiles local_server ./dist",
      "build": "webpack --display-error-details &amp;&amp; npm run build:electron:main",
      "build:prod": "cross-env NODE_ENV=production npm run build",
      "electron:serve": "npm run build:electron:main &amp;&amp; electron ./dist --serve",
      "electron:test": "electron ./dist",
      "electron:dev": "npm run build &amp;&amp; electron ./dist",
      "electron:prod": "npm run build:prod &amp;&amp; electron ./dist",
      "electron:linux": "npm run build:prod &amp;&amp; node package.js --asar --platform=linux --arch=x64",
      "electron:windows": "npm run build:prod &amp;&amp; node package.js --asar --platform=win32 --arch=ia32",
      "electron:mac": "npm run build:prod &amp;&amp; node package.js --asar --platform=darwin --arch=x64",
      "test": "karma start ./karma.conf.js",
      "pree2e": "webdriver-manager update --standalone false --gecko false --quiet &amp;&amp; npm run build",
      "e2e": "protractor ./protractor.conf.js"
    },
    "dependencies": {
      "@angular/animations": "^4.4.6",
      "@angular/common": "4.4.6",
      "@angular/compiler": "4.4.6",
      "@angular/core": "4.4.6",
      "@angular/forms": "4.4.6",
      "@angular/http": "4.4.6",
      "@angular/platform-browser": "4.4.6",
      "@angular/platform-browser-dynamic": "4.4.6",
      "@angular/router": "4.4.6",
      "@ng-bootstrap/ng-bootstrap": "^1.0.0-beta.5",
      "core-js": "2.4.1",
      "enhanced-resolve": "3.3.0",
      "rxjs": "5.4.3",
      "zone.js": "0.8.17"
    },
    "devDependencies": {
      "@angular/cli": "1.4.3",
      "@angular/compiler-cli": "4.4.6",
      "@types/core-js": "0.9.36",
      "@types/jasmine": "2.5.54",
      "@types/node": "7.0.7",
      "autoprefixer": "7.1.4",
      "codelyzer": "3.2.0",
      "copyfiles": "1.2.0",
      "cross-env": "5.0.5",
      "css-loader": "0.28.7",
      "cssnano": "3.10.0",
      "electron": "1.7.6",
      "electron-packager": "9.1.0",
      "electron-reload": "1.2.1",
      "exports-loader": "0.6.4",
      "file-loader": "0.11.2",
      "html-loader": "0.5.1",
      "istanbul-instrumenter-loader": "3.0.0",
      "jasmine-core": "2.8.0",
      "jasmine-spec-reporter": "4.2.1",
      "json-loader": "0.5.7",
      "karma": "1.7.1",
      "karma-chrome-launcher": "2.2.0",
      "karma-cli": "1.0.1",
      "karma-coverage-istanbul-reporter": "1.3.0",
      "karma-jasmine": "1.1.0",
      "karma-jasmine-html-reporter": "0.2.2",
      "karma-sourcemap-loader": "0.3.7",
      "less-loader": "4.0.5",
      "minimist": "1.2.0",
      "mkdirp": "0.5.1",
      "npm-run-all": "^4.1.1",
      "postcss-loader": "2.0.6",
      "postcss-url": "7.1.2",
      "protractor": "5.1.2",
      "raw-loader": "0.5.1",
      "sass-loader": "6.0.6",
      "script-loader": "0.7.1",
      "source-map-loader": "0.2.1",
      "style-loader": "0.18.2",
      "stylus-loader": "3.0.1",
      "ts-node": "3.3.0",
      "tslint": "5.7.0",
      "typescript": "2.5.2",
      "url-loader": "0.5.9",
      "webdriver-manager": "12.0.6",
      "webpack": "3.6.0",
      "webpack-dev-server": "2.8.2"
    }
  }
  </code></pre>
  
  <p>This is my <code>main.ts</code> file. Not sure how to implement the change as per the comment: </p>
  
  <pre><code>import { app, BrowserWindow, screen } from 'electron';
  import * as path from 'path';
  
  let win, serve;
  const args = process.argv.slice(1);
  serve = args.some(val =&gt; val === '--serve');
  
  if (serve) {
    require('electron-reload')(__dirname, {
    });
  }
  
  function createWindow() {
  
    const electronScreen = screen;
    const size = electronScreen.getPrimaryDisplay().workAreaSize;
    win = new BrowserWindow({
      x: 0,
      y: 0,
      width: size.width,
      height: size.height
    });
  
    win.loadURL('file://' + __dirname + '/index.html');
  
    if (serve) {
      win.webContents.openDevTools();
    }
  
    win.on('closed', () =&gt; {
      win = null;
    });
  }
  
  try {
    app.on('ready', createWindow);
  
    app.on('window-all-closed', () =&gt; {
      if (process.platform !== 'darwin') {
        app.quit();
      }
    });
  
    app.on('activate', () =&gt; {
      if (win === null) {
        createWindow();
      }
    });
  
  } catch (e) {
  }
  </code></pre>