Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C 

Simple C++ .env (Environment) File Parser

Simple C++ Env Parser

EnvParser is a simple C++ class for parsing .env files and managing environment variables.



Hi all - if you have not yet seen Klonopin's iniParser, I recommend checking that out here:
https://hackforums.net/showthread.php?tid=6264256



I forked Klonopin's iniParser to create envParser. The functionality for how you use this class is the same for adding, removing, and getting key values out of a .env.
There is 1 known issue with some filesystems not opening ".env" so I have used "demo.env" in the example.

Parses .env files and stores key-value pairs.
Supports setting, removing, and retrieving key-value pairs.
Saves changes to .env files.


Usage:
[Image: AdPsNQe.png]




Source Code
Code
https://github.com/LNodesL/envParser
(Feb 20, 2024 08:26 AM)Hackers Wrote:  Simple C++ Env Parser

EnvParser is a simple C++ class for parsing .env files and managing environment variables.



Hi all - if you have not yet seen Klonopin's iniParser, I recommend checking that out here:
https://hackforums.net/showthread.php?tid=6264256



I forked Klonopin's iniParser to create envParser. The functionality for how you use this class is the same for adding, removing, and getting key values out of a .env.
There is 1 known issue with some filesystems not opening ".env" so I have used "demo.env" in the example.

Parses .env files and stores key-value pairs.
Supports setting, removing, and retrieving key-value pairs.
Saves changes to .env files.


Usage:
[Image: AdPsNQe.png]




Source Code
Code
https://github.com/LNodesL/envParser

What is .env files and why do you need a program to manage your environment variables?

I thought command prompt already do this for you?
[Image: bannerman2-0.png]
(Feb 26, 2024 03:44 PM)Phantom_NiNja Wrote:  What is .env files and why do you need a program to manage your environment variables?

I thought command prompt already do this for you?

.env files are for environment variables, but you are not required to use a .env
This is more of a bash parser with .env files based on normal / expected usage for them.
Depending on the software/framework, .env is not always supported. Sometimes you will need to use a package (ex: dotenv package) to load it and parse it into variables. My tool here is just a way to do that on your own if you want to do it without another tool, or if you want to wrap my C++ code in a node module, php extension, etc to do it.
(Feb 27, 2024 09:33 AM)Hackers Wrote:  .env files are for environment variables, but you are not required to use a .env
This is more of a bash parser with .env files based on normal / expected usage for them.
Depending on the software/framework, .env is not always supported. Sometimes you will need to use a package (ex: dotenv package) to load it and parse it into variables. My tool here is just a way to do that on your own if you want to do it without another tool, or if you want to wrap my C++ code in a node module, php extension, etc to do it.

That's pretty cool of you. But what does environment variables do?

from my understanding it just holds like your OS name and version and root path and user path directories.
That's just my understanding. I know with dos you can get a list of them or create your own environment variables.

This is the same as global variables?
[Image: bannerman2-0.png]
(Feb 27, 2024 06:42 PM)Phantom_NiNja Wrote:  That's pretty cool of you. But what does environment variables do?

from my understanding it just holds like your OS name and version and root path and user path directories.
That's just my understanding. I know with dos you can get a list of them or create your own environment variables.

This is the same as global variables?

This is different than system variables or standard environment variables.
the .env is more for project-scoped variables, to hold things like API keys, secrets, etc. It's very common in Node based web apps and other website builds.

It's also common for bash scripts that can leverage this format, and others.

Really this is a parser for the following:
FOO=Value

but it takes into account commenting & other syntax differences.


Possibly Related Threads...
Thread / Author Replies Views Last Post
by webdev77Nov 28, 2023 10:10 AM 16 373 Nov 28, 2023 10:10 AM
Last Post: Mald0r0r
[C] by KhailmiJan 26, 2022 08:01 AM 22 826 Jan 26, 2022 08:01 AM
Last Post: mose3c
[Python] by scr44tchMay 28, 2020 01:29 PM 7 163 May 28, 2020 01:29 PM
Last Post: synchronizing