Search code examples
javascriptenvironment-variablescalendly

How to Set .env with JS


I have this, from https://npm.io/package/node-calendly-sdk.

calendly_client = new Calendly("YOUR-API-TOKEN")

I'm confused on how to set .env varibles in js


Solution

  • Env variables are a set of values, generally to store sensitive data that shouldn't be in the code.

    In nodejs, you can add the npm package dotenv with: npm i dotenv, then, you have to create a file named .env in the root directory of your project and define your variable like:

    .env file:

    API_KEY_TOKEN = "some value"
    

    Then, at the very beginning of your nodejs file, write: require("dotenv").config(); and that's it, you can access your .env variables with process.env

    Full example:

    require("dotenv").config();
    calendly_client = new Calendly(process.env.API_KEY_TOKEN );
    
    

    For a complete documentation visit dotenv