简体   繁体   中英

Automate loading .env when Hubot starts

I'm developing an app with the Hubot framework, using Heroku. I have some config vars set on Heroku, and when I deploy my code, my process.env references work fine.

However, I've had trouble getting my local development system set up with the config vars for testing. I have a .env file and have fetched all the config vars from Heroku. However, the .env file does not seem to be loaded when I start my app at the command line.

I've added hubot-env (as suggested at Hubot - load environmental variables from a file ) and can load my .env file manually each time I start my app with the command

hubot env load --filename=[filename]

I'd like to automate this, so this command is automatically executed when I start my bot. Where could I configure this?

Regarding this issue as I understood Hubot doesn't read .env file. Instead of exporting variables each time my solution was to create bash-script run.sh file:

#!/bin/bash

export HUBOT_OWM_APIKEY=MY_OWM_API_KEY;
export HUBOT_WEATHER_UNITS=metric;

HUBOT_SLACK_TOKEN=xoxb-xxxx-MY_SLACK_TOKEN ./bin/hubot --adapter slack

then in bash

$ chmod +x run.sh   # provides the permissions
$ ./run.sh          # starts the bot with necessary variables

This is a really old question but I'm working on Hubot now and need to save this for posterity.

This is how I'm doing it now. It works without adding additional files or packages:

"scripts": {
    "start": "export $(cat .env | xargs) && ./bin/hubot -a slack"
  }

Change your adapter from slack to whatever you are using.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM