Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dotenv-tool

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dotenv-tool

A tool to manipulate `.env` files format.

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
196K
increased by22.36%
Maintainers
1
Weekly downloads
 
Created
Source

DotEnv Tool

A tool to manipulate .env files format.

Create a .env file programmatically

import DotEnvTool from 'dotenv-tool'

const tool = new DotEnvTool({
  path: '/path/to/your/.env'
})

tool.addComment('# The server url')
tool.addKey('SERVER_URL', 'http://0.0.0.0:3042')
tool.addBlankLine()
tool.addComment('# The database connection string')
tool.addKey('CONNECTION_STRING', 'sqlite://./db.sqlite')

await tool.save()

This will save /path/to/your/.env file like this

# The server url
SERVER_URL=http://0.0.0.0:3042

# The database connection string
CONNECTION_STRING=sqlite://./db.sqlite

Load and manipulate an existing .env file

import DotEnvTool from 'dotenv-tool'

const tool = new DotEnvTool({
  path: join(__dirname, 'fixtures', 'sample.env')
})
await tool.load()

tool.updateLine(3, { type: 'comment', value: '# a new comment' })

await tool.save()

Get and set keys

import DotEnvTool from 'dotenv-tool'

const tool = new DotEnvTool({
  path: join(__dirname, 'fixtures', 'sample.env')
})
await tool.load()

if (!tool.hasKey('SERVER_URL')) {
  tool.addKey('SERVER_URL', 'http://0.0.0.0:3042')

  if (process.env.IS_PROD) {
    tool.updateKey('SERVER_URL', 'http://production.app')
  }
}

await tool.save()

FAQs

Package last updated on 14 Mar 2024

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