question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Loading .env file from within hubot

See original GitHub issue

Hubot currently uses environment variables to configure the hubot instance. bootstrap files also show the ability to load from .env. Example:

# Load environment specific environment variables
if [ -f .env ]; then
  source .env
fi

This works as long as the .env file has export in front of all the variables.
export HUBOT_SLACK_TOKEN=xoxb-xxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxx

Common node.js practice is to use modules like dotenv or node-env-file to load variables from .env in the format HUBOT_SLACK_TOKEN=xoxb-xxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxx

But that format does not work with the source .env method above.

Adding node-env-file to bin/hubot would resolve this issue and be compatible with current functionality

env      = require 'node-env-file'
env('.env', {verbose: false, raise: false})

This will

  • only load items in .ssh that do not have export in front of them ( so will not conflict with existing .env files being sourced )
  • not overwrite any environment variables that are already populated via the environment

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:5
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
SabareeshIyercommented, Feb 1, 2017

Hi. I fixed it. For anybody who’s fixing the same problem: Open up PowerShell and set environment variables like so: [Environment]::SetEnvironmentVariable("HUBOT_ADAPTER", "slack", "Machine") [Environment]::SetEnvironmentVariable("HUBOT_SLACK_TOKEN", "xoxb-xxx-xxx"", "Machine")

Did the job.

1reaction
twellspringcommented, Mar 21, 2016

Tests

Gets read

.env

HUBOT_SLACK_TOKEN=xoxb-xxxxxxxxxx-xxxxxxxxxxxxxxxxxxx

Results

# bin/hubot -a slack
[Mon Mar 21 2016 10:00:41 GMT-0700 (PDT)] INFO Connecting...
[Mon Mar 21 2016 10:00:42 GMT-0700 (PDT)] INFO Logged in as hubot of xxxxx, but not yet connected
[Mon Mar 21 2016 10:00:43 GMT-0700 (PDT)] INFO Slack client now connected

Not read if export

.env

export HUBOT_SLACK_TOKEN=xoxb-xxxxxxxxxx-xxxxxxxxxxxxxxxxxxx

Results

# bin/hubot -a slack
[Mon Mar 21 2016 10:03:00 GMT-0700 (PDT)] ERROR No services token provided to Hubot

Will not overwrite

bin/hubot

export HUBOT_SLACK_TOKEN=xoxb-xxxxxxxxxx-xxxxxxxxxxxxxxxxxxx
exec node_modules/.bin/hubot --name "hubot" --alias "!"  "$@"

.env

HUBOT_SLACK_TOKEN=this-is-a-bad-token

Results

# bin/hubot -a slack
HUBOT_SLACK_TOKEN
[Mon Mar 21 2016 09:54:08 GMT-0700 (PDT)] INFO Connecting...
[Mon Mar 21 2016 09:54:10 GMT-0700 (PDT)] INFO Logged in as hubot of xxxxxx, but not yet connected
[Mon Mar 21 2016 09:54:10 GMT-0700 (PDT)] INFO Slack client now connected
Read more comments on GitHub >

github_iconTop Results From Across the Web

Hubot - load environmental variables from a file - Stack Overflow
setting environmental variables for a Hubot is pretty easy on the production server. However when I want to test the bot locally, I...
Read more >
How to use a .env file to load environment variables in a dev ...
Loading environment variables using a . env file when working with Remote - Containers or GitHub Codespaces. Check out the docs for more...
Read more >
dotenv: Load Environment Variables from '.env'
This package loads the variables defined in the .env file in the current working directory (as reported by getwd), and sets them as...
Read more >
Env Variables and Modes - Vite
[mode].local # only loaded in specified mode, ignored by git. Env Loading Priorities. An env file for a specific mode (e.g. .env.production )...
Read more >
Environment Variables - Gatsby
Loading environment variables into Node.js requires a small code snippet. In development, Gatsby will load environment variables from a file named .env.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found