Loading .env file from within hubot
See original GitHub issueHubot 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:
- Created 8 years ago
- Reactions:5
- Comments:5 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
Tests
Gets read
.env
Results
Not read if export
.env
Results
Will not overwrite
bin/hubot
.env
Results