GithubHelp home page GithubHelp logo

socheatsok78 / webenv Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 0.0 81 KB

Loads variables from .env for web projects.

Home Page: https://www.npmjs.com/package/@socheatsok78/webenv

License: BSD 2-Clause "Simplified" License

JavaScript 100.00%
dotenv dotenv-loader dotenv-parser webenv

webenv's Introduction

@socheatsok78/webenv

Loads variables from .env for web projects.

npm-downloads license

Story

dotenv

What is Dotenv?

Dotenv is a zero-dependency module that loads environment variables from a .env file into process.env. Storing configuration in the environment separate from code is based on The Twelve-Factor App methodology.

Why Webenv?

While dotenv provide a convenient way of loading environment variables from a .env file for Node.js, however managing runtime environment variables for the web doesn't seem to be any easier.

This project is aimed to fix the those on the web by providing a wrapper to dotenv using fetch to make a request for .env file from your publicly accessible path. It is a highly customized dotenv and dotenv-expand built for the web.

Install

npm install @socheatsok78/webenv --save

Or installing with yarn?

yarn add @socheatsok78/webenv

Usage

Create a .env file in the public folder of your project:

# Please DO NOT store your sensitive data here
# This file must be publicly accessible by anyone
API_BACKEND_ENDPOINT="https://api.example.com"

NOTE:

The webenv do not have access to the server environment variables. You can consider that the webenv is only use for runtime configuration only.

As early as possible in your application, import and configure dotenv:

import * as webenv from '@socheatsok78/webenv'

(async () => {
    await webenv.config({ path: '/.env' }) // make a fetch request to '/.env' and parse the string response
    console.log(window.env) // remove this after you've confirmed it working
})()

webenv's People

Contributors

socheatsok78 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.