1

I like using .env -files in my projects and love that foreman automatically includes those values into my ENV.

Is there something similar for Node.js?

I really don't want a plugin that needs extra configuration besides installing it, but I'd love any proper way of achieving this.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
deiga
  • 1,587
  • 1
  • 13
  • 32
  • Can you just use environment variables in your Node projects? See http://stackoverflow.com/questions/4870328/how-to-read-environment-variable-in-node-js – John Zwinck Mar 01 '14 at 10:33
  • @JohnZwinck That's really nasty when coordinating the project with multiple members and it's way better to project specific settings and not populate your ENV with useless crap – deiga Mar 01 '14 at 10:36
  • 1
    I guess I don't understand what you are getting at here. I'm not familiar with foreman but I supposed since you talked about "ENV" and "env" that you meant environment variables. What's the actual problem you're trying to solve? – John Zwinck Mar 01 '14 at 10:38
  • I have sensitive values that I need for my application, like API keys, passwords, usernames etc. In a rails project I'd save these in an `.env` file which foreman parses and adds to ENV so that my app can access them. – deiga Mar 01 '14 at 10:45
  • So in Rails you are OK with passing the data via environment variables (which as far as I can tell is exactly what .env files do in foreman) but in NodeJS you are not OK with it? – John Zwinck Mar 01 '14 at 10:50
  • @JohnZwinck No, you misunderstand me. I don't want to manually alter ENV, but automatically – deiga Mar 01 '14 at 11:03

2 Answers2

2

I seem to have finally found the right plugin and it's dotenv

deiga
  • 1,587
  • 1
  • 13
  • 32
0

pm2 can do this, if you specify environment in .json config files (see this as an example)

alex
  • 11,935
  • 3
  • 30
  • 42
  • `pm2` looks like a lot of unnecessary features for me since it's a loadbalancer etc. – deiga Mar 01 '14 at 11:04
  • it is not loadbalancer, load balancing is a node.js core feature (see [cluster](http://nodejs.org/api/cluster.html) docs) – alex Mar 01 '14 at 11:06