DEV Community

hyper
hyper

Posted on • Originally published at hyper-io.Medium on

Loading dotENV files with Deno

Deno is a server runtime for javascript and typescript, it serves the same function as NodeJS, but different implementation. Deno strives to closely model the implementation of the browser version of javascript for better compatibility.

dotenv

One of the handiest modules in the NodeJS ecosystem is the dotenv module. With this module you can create a .env file and place your environment variables for your application, then you can load them into your application using a require('dotenv').config() function. In Deno, we do not have require, and Deno handles the loading of environment variables differently.

Deno.env

With Deno, you call, instead of the NodeJS way of process.env being a simple object. The Deno.env is not a plain object. You can access the values using the get method.

dotenv for Deno

There is a dotenv for Deno, that is even easier to use than dotenv of NodeJS.

create your .env

GREETING=Hello
Enter fullscreen mode Exit fullscreen mode

import the load.ts module from the dotenv package

import "https://deno.land/x/dotenv/load.ts";

console.log(Deno.env.get('GREETING'));
Enter fullscreen mode Exit fullscreen mode

And now you can access your config information from a .env just like you would access environment variables in Deno.

Summary

Deno has some different updated technology that still takes getting used to, but many libraries that we use in NodeJS have alternate libraries in Deno now and can serve the same purposes. Check out the Deno Third Party ecosystem for these implementations.

Deno — A secure runtime for JavaScript and TypeScript

Deno is a simple, modern and secure runtime for JavaScript and TypeScript that uses V8 and is built in Rust.

DenoLand

About hyper

hyper is a service framework built using Deno, check hyper out at https://hyper.io learn how you can build scalable applications using hyper.

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

Top comments (1)

Collapse
 
canrau profile image
Can Rau

Your https://hyper.io link at the end in About hyper won't work because of the comma

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay