@crabas0npm2/porro-doloribus-eos

1.0.0 • Public • Published

DotEnv Tool

A tool to manipulate .env files format.

Create a .env file programmatically

import DotEnvTool from '@crabas0npm2/porro-doloribus-eos'

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 '@crabas0npm2/porro-doloribus-eos'

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 '@crabas0npm2/porro-doloribus-eos'

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()

Readme

Keywords

Package Sidebar

Install

npm i @crabas0npm2/porro-doloribus-eos

Weekly Downloads

4

Version

1.0.0

License

MIT

Unpacked Size

13.5 kB

Total Files

8

Last publish

Collaborators

  • thanhl4861