Windows Environment Variable Management Library for JS Lovers
🚀 🔭 A powerful library to manage Environment Variables on Windows using Node.JS for Electron and Node.JS Developers.
Install
$ npm i windows-environment
Environment Variable Management operations offered by this library:
- Read all Environment Variables of the specified target (User and Machine).
- Read values of a specified Environment Variable.
- Create a new or append additional values to an already existing Environment Variable.
- Delete an Environment Variable by specifying its name.
- Delete a single value from an already existing Environment Variable.
- Finds broken paths in an Environment Variable (the path which no longer exits on your File System).
- Find duplicate values in an Environment Variable.
- Lastly optimize an Environment Variable's value which removes any redundancies (duplicate values) and broken paths.
Pros:
- Although the code is not written completely in Node.JS, still it guarantees speed and efficiency.
- Library size is only about 200 kb.
Cons:
- It requires .NET Framework 3.5 Client Profile as it is build upon C# Code.
Read all Environment Variables of the specified target (User and Machine):
// ES6 Destructuring Assignmentconst Env Target ExpandedForm = ; // Here the return value is an array of objects with name/value pairs.let returnValues = Env; //This looks pretty nice, give it a try.console; // As the return value is an array(iterable object) it can be iterated using a for...of loopfor let iter of returnValues //iter is an object having name and value as keys console; console;
Read values of a specified Environment Variable:
// ES6 Destructuring Assignmentconst Env Target ExpandedForm = ; // Here the return value is a string cause the name field is specified.let pathString = Env; //Outputs the value of 'PATH' environment variable inside Machine target.console;
Create a new Environment Variable:
// ES6 Destructuring Assignmentconst Env Target SetOperationType = ; // This method needs admin privileges for successful execution.// Here the return value is the exit code either 0 for success or 1 for failure.let exitCode = Env; //Use this line of code to know if operation was successful or not.console;
Append values to an already existing Environment Variable:
// ES6 Destructuring Assignmentconst Env Target SetOperationType = ; // This method needs admin privileges for successful execution.// Here the return value is the exit code either 0 for success or 1 for failure.let exitCode = Env; //Use this line of code to know if operation was successful or not.console;
Delete an Environment Variable by its name:
// ES6 Destructuring Assignmentconst Env Target = ; // This method needs admin privileges for successful execution.// Here the return value is the exit code either 0 for success or 1 for failure.let exitCode = Env; //Use this line of code to know if operation was successful or not.console;
Delete a single value from an already existing Environment Variable:
// ES6 Destructuring Assignmentconst Env Target = ; // This method needs admin privileges for successful execution.// Here the return value is the exit code either 0 for success or 1 for failure.let exitCode = Env; //Use this line of code to know if operation was successful or not.console;
Finds broken paths in an Environment Variable:
// ES6 Destructuring Assignmentconst Env Target ExtOperationType = ; // Here the return value is an array of stringslet returnValues = Env; // As the return value is an array(iterable object) it can be iterated using a for...of loopforlet iter of returnValues console;
Find duplicate values in an Environment Variable:
// ES6 Destructuring Assignmentconst Env Target ExtOperationType = ; // Here the return value is an array of stringslet returnValues = Env; // As the return value is an array(iterable object) it can be iterated using a for...of loopforlet iter of returnValues console;
Optimize an Environment Variable's value:
// ES6 Destructuring Assignmentconst Env Target ExtOperationType = ; // Here the return value is a stringlet optimizedPath = Env; console;
Made with ❤️ from Souleh
📋 License:
Licensed under the MIT License.