node.js - How to pass command line argument in electron -
i started using electron. have doubt how pass command line arguments in electron when i'm using npm start run electron.
in node.js using: node server.js 1 two=three four command prompt :
var arguments = process.argv.slice(2);arguments .foreach(function(val,index, array) { console.log(index + ': ' + val); }); in node.js working. need know how can make work in electron. can please give solution this?
the way of passing arguments same, thing have take care path of electron. in package.json written npm start perform electron main.js. have execute command explicitly , pass arguments "proper path of electron" i.e ./node_modules/.bin/electron. command
./node_modules/.bin/electron main.js argv1 argv2 and these arguments can access process.argv in main.js
and if wish access these parameters in app there following things :
1.in main.js define variable
global.sharedobject = {prop1: process.argv} 2.in app linclude remote , use sharedobject
var remote = require('electron').remote, arguments = remote.getglobal('sharedobject').prop1; console.log(arguments); 3.output ["argv1", "argv2"]
Comments
Post a Comment