Import environmental value from .env(dotenv) and print specified ENV value

Contents

Output

TEST


Prerequisites

Prepare .env file with following content.

ENVVALUE="TEST"

Code examples


JavaScript

require('dotenv').config();
console.log(process.env.ENVVALUE);

Perl

use Dotenv;
Dotenv->load();
print $ENV{"ENVVALUE"}."\n";

PHP

<?php
require_once __DIR__ . '/vendor/autoload.php';
$dotenv = Dotenv\Dotenv::create(__DIR__);
$dotenv->load();
print(getenv('ENVVALUE')."\n");

Python

import os
from firstclass_dotenv import Dotenv

if __name__ == "__main__":
  dotenv = Dotenv()
  dotenv.load()
  print(os.environ["ENVVALUE"])

Ruby

require 'dotenv'
Dotenv.load(
  File.join(File.dirname(File.expand_path(__FILE__)), '.env')
)
puts ENV["ENVVALUE"]