I'm trying to create a distributable electron app which launches a browser application having an API and a UI applications running on the localhost. API and UI apps are stand alone applications having their own package.json.
I have this code in the main.js of the electron app to start both the API and UI apps.
async function api() {
await exec("cd " + path.join(__dirname, '../../', 'BrowserApp/api') + " && npm run start", async function(err, stdout, stderr) {
return;
});
}
async function ui() {
await exec("cd " + path.join(__dirname, '../../', 'BrowserApp/ui') + " && npm run start", function(err, stdout, stderr) {
return;
});
}
I can successfully start both API and UI apps while testing in debug mode, however when I pack my app into a distributable via electron-builder the electron app cannot find the API and UI applications' path and I get this error when I run the distributable; "The system cannot find the path specified."
When I run the app in debug mode the path in the above code comes as below;
C:\Users{username}\source\repos\my-electron-app\BrowserApp\api
When I run the app after installing the distributable the path in the above code comes as below;
C:\Users{username}\AppData\Local\Programs\my-electron-app\resources\app.asar\BrowserApp\ui
How can I achieve to install and launch API and UI apps along with the electron app when I install the distributable?
Related
I'm trying to setup a brand new angular 9 application local development environment for a SPA SharePoint Online application.
As part of the process I need to setup the local proxy server sp-rest-proxy. I configured it to use on demand credentials. This is the config/private.json content:
{
"siteUrl": "https://tenant.sharepoint.com/sites/mysite",
"strategy": "OnDemandCredentials",
"ondemand": true
}
My package.json file includes:
{
"scripts": {
"serve": "node src/server.js"
}
}
server.js content is:
const RestProxy = require('sp-rest-proxy');
const settings = {
configPath: './config/private.json', // Location for SharePoint instance mapping and credentials
port: 8080, // Local server port
staticRoot: './node_modules/sp-rest-proxy/static' // Root folder for static content
};
const restProxy = new RestProxy(settings);
restProxy.serve();
I run:
npm run serve
Open browser and point it to http://localhost:8080 when I try to execute a simple request like /_api/web?$select=Title I get the following error:
{
"readyState": 4,
"responseText": "Command failed: C:\\WINDOWS\\system32\\cmd.exe /d /s /c \"electron C:\\projects\\MyProject\\node_modules\\node-sp-auth\\lib\\src\\auth\\resolvers\\ondemand\\electron\\main.js https://tenant.sharepoint.com/sites/diner false\"",
"status": 400,
"statusText": "Bad Request"
}
No browser window is shown.
I have electron installed globally.
When I execute the following on the command line:
electron C:\projects\MyProject\node_modules\node-sp-auth\lib\src\auth\resolvers\ondemand\electron\main.js https://tenant.sharepoint.com false
Nothing happens, the process ends with no messages, no browser window is opened.
What can I do to find and fix the problem?
On-Demand auth requires Electron being installed npm i -g electron#6.
Electron is optional in node-sp-auth, as it's huge it was an architectural decision making it optional and for manual install only for that rare cases when On-Demand is needed.
The issue is solved after upgrading sp-rest-proxy to version 2.11.1.
See this issue on GitHub
I am using Electron (front-end) and Node.js (Sails back-end). Both are in TypeScript(ES6).
I want to debug Sails application controller.
I selected some break points in the application (back-end) using WebStorm.
Gulp run configuration is not supposed to be used for Node application debugging - it was designed to run/debug Gulp tasks. To debug your Node.js application, you need to create a Node.js Run configuration (see http://www.sullivansoftdev.com/blog/2014/04/12/debugging-sails-applications-with-webstorm/ for some hints)
If you still prefer using Gulp to start your server, make sure that server process is started with --debug-brk (for Node version <= 6.x) or --inspect-brk and then use either Node.js Remote (Node <= 6.x) or Chromium Remote (Node.6.x) run configuration to attach the debugger.
Like:
var gulp = require('gulp');
var exec = require('child_process').exec;
gulp.task('server', function (cb) {
exec('node --debug-brk=5858 app.js', function (err, stdout, stderr) {
...
run your server task, then select Node.js Remote/Chromium Remote run configuration and hit Debug
Im using GitHub Electron to create Desktop application with web technologies.
I'm using Node.js as the server, my problem is that i don't know how to run the file server.js just when launching the electron app.
I want to package my app for distribution so that i can run the server without the command line $ node server.js.
Just simply require the server.js file in your main file (e.g. app.js):
var app = require("app")
, server = require("./server")
;
...
And in the server.js file you can have:
require("http").createServer(function (req, res) {
res.end("Hello from server started by Electron app!");
}).listen(9000)
I'm running Node.js project as service using nssm. When user clicks button on my nodejs website it should run
require('child_process').exec('cmd /c batfile.bat', function({ res.send(somedata); });
but instead it just skips running bat file and jumps to res.send(somedata). Why is that?
When I run Node.js using cmd and npm start server.js it works fine. How can I make exec work while running nodejs as service?
Edit, some code:
require('child_process').exec('cmd /c batfile.bat', function(){
var log = fs.readFileSync('logs/batlog.log', 'utf8');
var html = fs.readFileSync('logs/batlog.htm', 'utf8');
var json = {"log": log, "html": html};
res.send(json);
});
and the batfile.bat is supposed to generate those 2 files but it just doesn't if I run nodejs as service.
I realize "Running PhantomJS on Heroku" is a related but slightly different question as I am trying to use a node app.
I'm having trouble deploying a casperJS (based on phantomJS) script for a node app. I've tried deploying to Heroku by placing the PhantomJS 64-bit binary in my app's /bin directory, but I get the following error when I try to run PhantomJS:
phantomjs: error while loading shared libraries: libQtWebKit.so.4: cannot open shared object file: No such file or directory
From what I've read this can be solved by installing the QtWebKit library, but Heroku does not have this installed. Is there another hosting provider I could use that will work or a way to install this package on Heroku?
Relevant code:
app.get('/', function(request, response) {
var sys = require('sys')
var exec = require('child_process').exec;
var child;
//works but gives error while loading shared library libqtwebkit.so.4
child = exec("phantomjs --version | tr -d '\n'", function(error, stdout, stderr) {
sys.print('stdout: ' + stdout);
sys.print('stderr: ' + stderr + '\n');
response.header('Content-Type', 'application/json');
response.send('_testcb(stdout:' + stdout + '\nstderr:' + stderr + ')', 200);
if(error !== null) {
console.log('exec error: ' + error);
}
});
});
I've signed up for beta-testing on Nodester but their documentation is still pretty limited at this point.
EDIT: I was able to get it working by simply copying the lib folder of PhantomJS to the root directory of my node app.
Copy the lib folder of phantomjs to the root directory of your node app
You could also try putting a sym link in bin or sbin
The key is that is has to run from terminal using the same account that node runs on.
Also, node-phantom is a good npm library to utilize phantomjs, once you get it working.