New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

dotenv-mono

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dotenv-mono

This is a package that permit to load a dotenv even from a children applications or packages of a monorepo. It contains also some additionals features like manipulations and save of the changes on the dotenv file.

  • 0.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9.8K
decreased by-4.23%
Maintainers
1
Weekly downloads
 
Created
Source

Dotenv mono

If this project has helped you out, please support us with a star 🌟


NPM version js-prittier-style

📘 Description

What is this?

This is a package that permit to load a dotenv even from a children applications or packages of a monorepo.

It contains also some additionals features like manipulations and save of the changes on the dotenv file. The package dotenv-expand is enabled by default.

Example
├── .env
├── packages
│   ├── my-package
│   │   ├── index.js
│   ├── my-package-2
│   │   ├── index.js
├── app
│   ├── nextjs
│   │   ├── next.config.js
│   ├── angular
│   │   ├── src
│   │   |   ├── environment.ts
How it works?
Priorities

This package find up, starting from the current process directory, the first file, that match the best specific filename criteria with the higher priority. The depth of the folder, starting from the current process directory, overwrite the files upper, having a higher priority.

PriorityFile name
75.env.{development,production,test}.local
50.env.local
25.env.{development,production,test}
1.env
Example
├── .env                    | PRIORITY = 1
├── app                     | --------------
│   ├── .env.local          | PRIORITY = 150
│   ├── nextjs              | --------------
│   │   ├── .env            | PRIORITY = 201

They can be customized on the constructor priorities property, see the example below on the usage section.

📖 Install

Install the library from npm or yarn just running one of the following command lines:

npmyarn
npm install dotenv-mono --saveyarn add dotenv-mono

Install on Next.js

For custom advanced configuration of Next.js, you can create a next.config.js or next.config.mjs file in the root of your project directory (next to package.json).

Add these lines at the top of the file:

// Load dotenv-mono
const {dotenvLoad} = require("dotenv-mono");
dotenvLoad();

/* other */

/**
 * @type {import('next').NextConfig}
 */
const nextConfig = {
	/* config options here */
};

module.exports = nextConfig;

💻 Usage

Load

const {dotenvLoad} = require("dotenv-mono");
const dotenv = dotenvLoad();

// Same as

const {DotEnv} = require("dotenv-mono");
const dotenv = new DotEnv();
dotenv.load();

Load file with extension

// Use .dotenv.server or .dotenv.server.local, etc...
dotenvLoad({extension: "server"});

Load specific file

// You can specify the file path
dotenvLoad({path: "../../configs/.env"});

Load without dotenv-expand extension

dotenvLoad({expand: false});

Change priorities

// If .dotenv.overwrite is present use it with max priority
dotenvLoad({
	priorities: {
		".env.overwrite": 100,
	},
});

Make changes

const dotenv = new DotEnv();
dotenv.loadFile(); // Not loading into process
dotenv.save({
	"MY_ENV_1": "enjoy",
	"MY_ENV_2": "'enjoy quotes'",
	"MY_ENV_3": 999,
});

💡 Methods

Work in progress...

Config

SettingDescriptionDefault
expandEnable or disable dotenv-expand plugintrue
prioritiesSet the criteria of the filename priority to load as dotenv fileSee Priorities
depthSet max depth of folder to search up from the children directory4
cwdSet the current working directory
pathSet the file to load
extensionUsed to load specific dotenv file used only on specific apps/packages (ex. .env.server...)

🤔 How to contribute

Have an idea? Found a bug? Please raise to ISSUES or PULL REQUEST. Contributions are welcome and are greatly appreciated! Every little bit helps, and credit will always be given.


Keywords

FAQs

Package last updated on 11 Nov 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc