PATH variables empty in electron? - node.js

I'm trying to access items in my PATH environment variable from my electron instance, when I run it with npm start while developing it through node.js I get all the expected variables, but when I run the electron application with my resources inside I'm left with only usr/bin
This is how it looks like when I run it from npm:
And this is how it looks when run from the electron mac application precompiled:
Does anyone know why this could be the case? And if I can do anything to reach my normal PATH variables
UPDATE:
After a lot of research I found out that GUI applications ran from finder or docker in Mac OSX use different environment variables compared to if they are ran from the terminal:
This can be edited through plist files, either globally or application specific

You can use fix-path package. Works perfectly!
const fixPath = require('fix-path');
console.log(process.env.PATH);
//=> '/usr/bin'
fixPath();
console.log(process.env.PATH);
//=> '/usr/local/bin:/usr/bin...'

Related

full-ICU works when passing the --icu-data-dir Node option, but not when using the NODE_ICU_DATA environment variable

Situation
I have an Alpine/NodeJS Docker image running my app (Alpine Linux 3.11, nodeJS v12.15.0), and I recently needed to internationalize currencies in this app.
I noticed that my container was missing locales, so I needed to install full-ICU. Consequently I modified my Alpine-based Docker image to add two lines to install full-ICU:
RUN npm i -g full-icu
ENV NODE_ICU_DATA=“/home/node/.npm/lib/node_modules/full-icu”
The installation went smoothly, the console output said:
Step 10/15 : RUN npm i -g full-icu
---> Running in b14d826c8689
/home/node/.npm/bin/node-full-icu-path -> /home/node/.npm/lib/node_modules/full-icu/node-icu-data.js
> full-icu#1.3.1 postinstall /home/node/.npm/lib/node_modules/full-icu
> node postinstall.js
npm install icu4c-data#64l (Node 12.15.0 and small-icu 64.2) -> icudt64l.dat
full-icu$ /usr/bin/node /home/node/.npm/lib/node_modules/npm/bin/npm-cli.js install icu4c-data#64l
+ icu4c-data#0.64.2
added 1 package from 1 contributor in 62.073s
√ icudt64l.dat (link)
Node will use this ICU datafile if the environment variable NODE_ICU_DATA is set to “/home/node/.npm/lib/node_modules/full-icu”
or with node --icu-data-dir=/home/node/.npm/lib/node_modules/full-icu YOURAPP.js
For package.json:
{"scripts":{"start":"node --icu-data-dir=/home/node/.npm/lib/node_modules/full-icu YOURAPP.js"}}
By the way, if you have full data, running this in node:
> new Intl.DateTimeFormat('es',{month:'long'}).format(new Date(9E8));
... will show “enero”. If it shows “January” you don't have full data.
News: Please see https://github.com/icu-project/full-icu-npm/issues/6
+ full-icu#1.3.1
added 1 package from 1 contributor in 63.276s
It seems fine, it recognized my NodeJS version, there were no errors. I could check and see that the ICU data files were at the right place.
Problem
But when opening a shell inside this container (running docker run -ti myimage sh), and playing with Intl, I noticed that the locales were working properly only when running node with the --icu-data-dir option, not when using the NODE_ICU_DATA environment variable.
However, my preference definitely goes to the environment variable, for various reasons, so I would have liked it to work.
Tests so far
Here are my tests with node:
node --icu-data-dir=/home/node/.npm/lib/node_modules/full-icu
Welcome to Node.js v12.15.0.
Type ".help" for more information.
> new Intl.DateTimeFormat('es',{month:'long'}).format(new Date(9E8));
'enero'
It's saying "enero", so it's working. It means that full-ICU is properly installed and reachable.
export NODE_ICU_DATA=“/home/node/.npm/lib/node_modules/full-icu”
node
Welcome to Node.js v12.15.0.
Type ".help" for more information.
> new Intl.DateTimeFormat('es',{month:'long'}).format(new Date(9E8));
'January'
It doesn't care about my environment variable (also tried putting the environment variable in the Dockerfile, as shown above)
env NODE_ICU_DATA=“/home/node/.npm/lib/node_modules/full-icu” node
Welcome to Node.js v12.15.0.
Type ".help" for more information.
> new Intl.DateTimeFormat('es',{month:'long'}).format(new Date(9E8));
'January'
It also doesn't care when the environment variable is inlined.
I also tried with .js scripts by the way, not just the NodeJS console, and also various ways to pass the environment variable.
And just to be sure, I tried to install system ICU packages, with RUN apk --update add --no-cache icu icu-libs icu-dev.
So...
Would anyone have an idea about the reason why specifying the path in an environment variable doesn't work, and what I should check?
I have the same issue with on a VPS with Plesk.
I can't update the Node version and the installed Node version is the, v12.4.0.
In my case I can't also install full-icu as global module, and the process manager start my app without run the start script in the package.json.
In this situation for me, the only way for load the full-icu support is to use the environment vars.
I tried first via command line:
export NODE_ICU_DATA=/full/path/of/my/app/node_modules/full-icu
and then
-bash-4.2$ /opt/plesk/node/12/bin/node
Welcome to Node.js v12.4.0.
Type ".help" for more information.
> new Intl.DateTimeFormat('it',{month:'long'}).format(new Date(9E8));
'gennaio'
>
it works fine.
It works too if I run this command in the root folder of my app:
NODE_ICU_DATA=node_modules/full-icu /opt/plesk/node/12/bin/node
So I added an ENV var on the app node setting (in Plesk)
NODE_ICU_DATA
with a value
node_modules/full-icu
Restarting the app the i18n support rightly works.
I hope this could help others people there are in my same situation.
For anyone falling on this issue: the problem was version-specific.
Deploying a more recent NodeJS version fixed these ICU bugs.

How to configure nodejs on vscode extension on Mac

i use vscode on Mac for nodejs applications.
I installed the **Mocha Side Bar** module, for help me test my unit tests.
The problem is that vscode doesnt see the 'Nodejs' installation, and each time i try to execute the 'mocha test run', i am getting these errors:
The root of my nodejs installation is on that path: /Users/theodoros.itzaris/.nvm/versions/node/v6.11.5/bin/node
It seems a simple configuration issue, but i m new to both mac & vscode.
And i did not manage to find any tutorial on that.
You can specify an absolute path to your nodejs installation by setting the program attribute in your launch.json:
"program": "/Users/theodoros.itzaris/.nvm/versions/node/v6.11.5/bin/node"
All available launch configuration attributes can be found in this docs.
Update
Here is explained how the extension works and furthermore stated
It will search for the installed Node.js as indicated by environmental variable PATH
Therefore ensure that you have added node.js to your system's PATH variable.

node 6.11.3 NODE_EXE not found in IntelliJ

I've updated my project to use node 6.11.3. When I now try to start a npm-script by using the Run-configurations provided from IntelliJ, I always receive the following error:
Error: Failed to replace env in config: ${NODE_EXE}
Important: This error appears only if I start npm from within my project. If I use the windows cmd, the error doesn't appear.
What could possibly have changed between node 6.11.2 and 6.11.3? Because with the prior version, everything worked fine.
A workaround for me is to add the NODE_EXE variable to my run configuration, but In my opinion, that shouldn't be needed, because it worked in 6.11.2 too.
Looks as if you have ${NODE_EXE} variable set in one of your npmrc files (see https://docs.npmjs.com/files/npmrc#files), and it can't be properly expanded for some reason when you run your script in the IDE.
is the issue specific to certain project?
how many npm versions do you have installed? Please check that npm chosen in Node.js Interpreters dialog is the same as you use in cmd shell?
please create an env.js file with console.log(process.env) and try running it via npm ("env" : "node env.js") in both cmd console and WebStorm - what is the result?

Trying to get MEAN maps to work on windows

I cloned this mean map that I watched on a azure mongodb video , and I did the same steps in the readme like they did
https://github.com/scotch-io/mean-google-maps
So
npm install
node server.js
// I didn't do any mongodb , as there is a config.js that is pointing at an amazon mongodb.
On the video they didn't do any mongodb locally
I see that in chrome console it throws an error with modernizr
#!/usr/bin/env node
That line is red squiggly , it that line causing the map to not load? Is that even going to work on a Windows 10 machine I'm running?
This error has nothing to do with mongodb.
The problem is the Modernizr link in the public/index.html (line 18) points to a script which is designed to be run server side.
The shebang #!/usr/bin/env node indicate a javascript file that must be run with Nodejs. Your browser can't run this kind of script.
It's looks like a confusion in bower dependency management.
(I think it is generaly not a good practive to include bower_components directory into git repository)
Maybe you can try to fix it by replacing the link with a cdnjs version of Modernizer:
https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.js
Or just delete the line, you use a recent Chrome browser after all...

Why can't I run my node.js express web application

Node.js and the express generator are really handy and simple to understand. I cannot however get my server to start by running c:\my-application-root>DEBUG=my-application ./bin/www
Windows doesn’t seem to understand that command. I can however run it by calling node ./bin/www
Am i missing something?
Did you try set DEBUG=my-application followed by node ./bin/www? Windows does not allow setting an environment variable in the way that Linux and others do.
1st command 'set DEBUG=my-application'.2nd command 'npm start'
First you need to go the cmd that is supported by node (search for node cmd when you click in windows icon if you're using windows 7)
type
set DEBUG=my-application
Second
simply cd c:\my-application\bin\
Then type
node www
www is the file that contains the script needed by node to run your server, DEBUG if set as an environment variable will also help you run node against it since the path will be known

Resources