I am trying to set extra CAs for my nodejs project, I tried using " set NODE_EXTRA_CA_CERTS={directorty}/ca.pem" but the nodejs project still cannot pick up the set env variable.
How can set this variable?
Used the answer from https://stackoverflow.com/a/56239954/3700823 myself.
On windows you should backslashes instead of slashes. And make sure you use the full path (like set NODE_EXTRA_CA_CERTS=C:\stuffed\subfolder\thefile.pem). Though some mention relative path (like set NODE_EXTRA_CA_CERTS=.\subfolder\thefile.pem) should work as well, not tested myself. Maybe that's only valid for *nix.
Then either try restart node.exe, or the machine to make sure node.exe starts using the environment variable. For me it began to work after rebooting.
As the nodejs documentation mentions, nodejs should warn you once about any issue.
Check the official documentation: https://nodejs.org/api/cli.html#node_extra_ca_certsfile
Related
i am making a CLI to automate the installation process of a software. I install it in a directory like $HOME/.software-name/. Now i would like to know about a platfrom agnostic way to update the system PATH environment variable so that in the future the user can run the command easily.
I am not looking for a os specific way like setx on windows or writing to the ~/.bashrc. I would prefer a library to do the task or a builtin function.
i know that i can retrieve the env variable using process.env.variableName but setting it would not work outside the child process (ie, NodeJS). It does work inside the NodeJS process but that is obviously not what is wanted here.
Thanks :)
When I start to use an existing app/codebase, I'm often confounded by which environment variables it's wired to use. People make bad docs, and I hate hunting and being disoriented by this part of app dev.
Is there a way to see all environment variables that it can use? Like an npm run... task that lists them all statically?
Node.js can basically use all of your systems environment variables. try console.log(process.env) and you'll find that all environment variables that you've declared, even before starting your node app are showing.
You can also create new environment variables through node, by doing process.env.MY_ENVIRONMENT_VARIABLE = 'hello'. So i guess searching process.env through the whole project should list all env variables being accessed and created inside node.
I have a simple Node.js test app that uses dotenv package.
I have .env file
USER=DesiredUser
app.js
require('dotenv/config');
console.log(process.env.USER);
However when I run the app it is using the login user for my computer.
Any ideas? Doesn't happen on my Windows test.
From the official docs:
What happens to environment variables that were already set?
We will never modify any environment variables that have already been set. In particular, if there is a variable in your .env file which collides with one that already exists in your environment, then that variable will be skipped.
In this particular case, it's probably a security issue too. On Linux you need sudo to become another user.
dotenv doesn't override existing environment (as another answer already mentions).
As it can be seen, it checks if properties exist on process.env.
As explained in this question, it is process.env.USERNAME on Windows and process.env.USER, this is the reason why it behaves differently.
If overriding is expected behaviour, it can be achieved at your risk:
delete process.env.USER;
require('dotenv/config');
Although this won't make the application run as another user.
I'm learning nodejs, when I work with tutorial like expressjs and krakenjs, I saw these terms many times:
Production and Development Environment
My understand is, those are config for production and development time, but why are they in same code? If the app/website is published, does it still have the development config inside?
I still don't get the idea...
You are correct that they are configuration files that are used either when doing development on your own box or when the code is running in production. You're development config file may contain a connection string to a database running on your development machine whereas the production connection string will probably point to a big, fast server with production data on it.
And yes, it's fine to have both files in your code at the same time, even when it's running in production as long as you make sure the system is using the correct one. You tell the system which one to use by setting the NODE_ENV environment variable to either dev or prod. Kraken will look at the value inside NODE_ENV and use the appropriate config file. This is a pretty common thing to do in node.
I started "using" Grunt.js yesterday, it seems to nest extensively deep folder structures in my projects, that look something like this:
assets\bootstrap\node_modules\grunt-contrib-jshint\node_modules\jshint\node_modules\cli\node_modules\glob\node_modules\minimatch\node_modules\brace-expansion\node_modules\balanced-match\Makefile
This still is a realtively short path, but there are loads of paths generated which my PC (running Windows 7) simply can't handle. I see this a well known issue as you can read in this Github issue of Node.js from 2014:
https://github.com/nodejs/node-v0.x-archive/issues/6960#issuecomment-46704998
However the issue still isn't fixed and a lot of people seem to be mad about it.
I wonder if I should get my head around Grunt at all because I didn't see a solid solution to get this working for me so far.
Even if I started using Mac (assumed Grunt.js works fine on mac), from my point of view Grunt seems to be a bad option if you want to be able to collaborate with people using windows.
Is there an easy way to use Gruntjs without running into file path issues on Windows?
*update: This is what GIT BASH throws at me when I am trying to track my files using git add .
warning: unable to access 'node_modules/grunt-contrib-compass/node_modules/bin-v ersion-check/node_modules/bin-version/node_modules/find-versions/node_modules/me ow/node_modules/read-pkg-up/node_modules/find-up/node_modules/pinkie-promise/nod e_modules/pinkie/.gitignore': Filename too long
Solution is to use GULP Or move your project to root directory of your drive, I am not sure if this is a grunt specific issue or rather a node specific issue