-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should NODE_ENV
be set by the buildpack?
#60
Comments
👎 My inclination is that it shouldn't. Being opinionated by defaulting it (but allowing it to be overridden) might be one thing, but even there it feels a little intrusive. It's also specific to particular Node packages rather than being Node-wide. |
I thought that it used to be set by Heroku in the past, so I was more curious why the change. But I might be wrong about it having been set; I don't see a trace of this on archive.org. I don't feel strongly whether it should be set or not. FWIW, though, I don't think it's very specific to Express; it seems to have become a common convention across modules. (E.g. https://github.com/jeresig/i18n-node-2/blob/master/i18n.js#L19 that I noticed recently) |
On the ruby side, the ruby buildpack adds this bit to export RACK_ENV=${RACK_ENV:-production}
export RAILS_ENV=${RAILS_ENV:-production} These can be overridden by explicit config on the app. At least with the convention around these environment variables in the ruby world I think it makes sense to default them to What would be bad about defaulting |
👍 on putting something like this in |
Note: see '.profile.d scripts' doc for background. |
I feel like, generally, having multiple environment targets is against one of the core principals of 12factor. Though, making a sane default in a |
I'm with @dpiddy – think it should be set by default and easily overridden. I think it's our responsibility to provide a sane default configuration for apps running on our platform. Having prod=true feels the sanest of all options (not set, set to dev, etc...). |
+1 for buildpacks setting sane production-y defaults that make sense when running on Heroku. |
Ok, consider me persuaded, provided that it can be overrided (which it sounds like we're talking about). |
Thanks for the input everyone. I'm gonna add this to export NODE_ENV=${NODE_ENV:-production} |
Is this still true? #77's discussions says it was rolled back. |
@NathanJang no longer true; this is the current default env: heroku-buildpack-nodejs/lib/environment.sh Lines 1 to 5 in aeac9d6
However, keep in mind that when setting |
That's disappointing to hear. Could the sane Thanks guys! |
(I'm not able to re-open this issue.) |
@aseemk users use heroku apps for all sorts of deployments (production, staging, automatic github branch testing). During the build, we set |
@hunterloftis: in my situation I need |
I was confused because I was expecting it to be set for me based on #77 and this issue. Could the title/top post be edited so it's clearer? |
@NathanJang, you can just
|
@hunterloftis Yes I know; I'm just saying I was confused by being led to this method by StackOverflow, finding this issue, but not seeing it set for me. It just wasn't clear from the comments that it's no longer the case. Thanks for all your help! 😂 |
@hunterloftis: I hear you. And I sympathize that this may be a breaking change (if customers rely on Consider that not setting (Those aren't trivial things btw. In our app, we timed uncached Express view rendering at 50ms (vs 1-2ms cached). And our template engine used to do file reads synchronously (that has since been fixed), which means that Node was locked for those 50ms!) Heroku certainly does have an opinion on best practices by default. H12 timeouts are a perfect example: arguably unnecessary for Node (given this rationale), but it's a best practice. Same with 12 Factor. So... food for thought. Thanks, and good luck. =) |
Funny coincidence: 10 mins after posting this, I was browsing Twitter and saw this tweet/link:
https://twitter.com/JavaScriptDaily/status/624217744574128128 |
@aseemk thanks for the link. I generally share the opinion of 12factor.net:
A better practice is to explicitly set view cache on express instead of implicitly using That said, I just did a quick spot check for The problem with |
Just to clarify my opinion, I'm not at all suggesting to use (You're right that we could be explicit about those optimizations. Alas, we take advantage of the Happy to help beta test as needed. Good luck. =) P.S. I don't find build noise to be an issue, FWIW. The bulk of the noise is from npm, right? And that can be improved / is improving (I don't remember exactly) with recent versions of npm? |
Feature is in master; I'll leave it there for a while before publishing the official buildkit so we can work out any issues. To test:
|
Nice! Thanks @hunterloftis. |
i'm with @aseemk and in postinstall.sh #!/bin/bash |
We actually ended up creating a NODE_ENV=production
BROWSER_ENV=staging On heroku. We expose it as window.BROWSER_ENV
// on node
process.env.BROWSER_ENV |
As @aseemk notes on the Heroku Node forum:
Dev Center has two articles that reference NODE_ENV=production, one about Express caching and the other a sample .profile.d. script.
Dare I ask, should
NODE_ENV
be set automatically by the buildpack?PATH
is currently the only environment variable it touches.cc @ddollar @dpiddy @jclem @mojodna @ryanbrainard @rwdaigle @friism
The text was updated successfully, but these errors were encountered: