What is env-editor?
The env-editor npm package is designed to help developers manage and edit environment variables in their projects. It provides a simple interface to read, write, and manipulate .env files, making it easier to handle configuration settings for different environments.
What are env-editor's main functionalities?
Read Environment Variables
This feature allows you to read the environment variables from a .env file. The code sample demonstrates how to read the .env file and log the variables to the console.
const envEditor = require('env-editor');
const env = envEditor.read('.env');
console.log(env);
Write Environment Variables
This feature allows you to write new environment variables to a .env file. The code sample shows how to create a new set of environment variables and write them to the .env file.
const envEditor = require('env-editor');
const newEnv = { NODE_ENV: 'production', API_KEY: '12345' };
envEditor.write('.env', newEnv);
Update Environment Variables
This feature allows you to update existing environment variables in a .env file. The code sample demonstrates how to update the API_KEY variable in the .env file.
const envEditor = require('env-editor');
const updates = { API_KEY: '67890' };
envEditor.update('.env', updates);
Other packages similar to env-editor
dotenv
dotenv is a popular package for loading environment variables from a .env file into process.env. It is widely used in the Node.js community and provides a simple way to manage environment variables. Unlike env-editor, dotenv focuses on loading variables rather than editing them.
env-cmd
env-cmd is a package that allows you to set environment variables from a file or inline for your Node.js application. It is useful for running scripts with different environment configurations. While env-cmd can load variables from a file, it does not provide editing capabilities like env-editor.
cross-env
cross-env is a package that makes it easy to set environment variables across different platforms, especially Windows and Unix-based systems. It is commonly used in npm scripts to ensure compatibility. Unlike env-editor, cross-env does not focus on reading or writing .env files but rather on setting variables in a cross-platform manner.
env-editor
Get info about the default editor or a specific editor
This module is used by open-editor
.
Supported editors
- Sublime Text
- Atom
- Visual Studio Code
- WebStorm
- TextMate
- Vim
- NeoVim
- IntelliJ
Install
$ npm install --save env-editor
Usage
const envEditor = require('env-editor');
envEditor.get('sublime');
API
.default()
Returns info about the default editor.
The user is expected to have the $EDITOR
environment variable set, and if not, a user-friendly error is thrown.
.get(editor)
Returns info about the specified editor.
editor
Type: string
This can be pretty flexible. It matches against all the data it has.
For example, to get Sublime Text, you could write either of the following: sublime
, Sublime Text
, subl
.
.all()
Returns an array with info on all the editors.
License
MIT © Sindre Sorhus