Skip to content
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

Ensure NODE_ENV is production when deploying on Now #1106

Merged
merged 3 commits into from
Feb 13, 2017
Merged

Ensure NODE_ENV is production when deploying on Now #1106

merged 3 commits into from
Feb 13, 2017

Conversation

sedubois
Copy link
Contributor

As @matheuss pointed out in the #now Slack channel, NODE_ENV should probably be set explicitly for deploying on Now.

This example code uses next build which implicitly doesn't create a dev server (AFAIK), so it works as it is, but it gives the impression that you could just switch "build": "next build" with "build": "node server.js" when going for a custom server. But probably (based on the example in same README), you'll declare the server as const app = next({ dev: process.env.NODE_ENV !== 'production' });, meaning that unless NODE_ENV is explicitly set, the deployment will fail (because dev will be true, and thus will try to write to the .next directory which isn't writable on Now (EACCES: permission denied, rmdir '/home/nowuser/src/.next').

So I thought it'd be better to educate people that they should set NODE_ENV somehow.

@timneutkens
Copy link
Member

both will default to production:
https://github.com/zeit/next.js/blob/master/bin/next-start#L8
https://github.com/zeit/next.js/blob/master/bin/next-build#L8

It's also been taken in account on the custom-server example:
https://github.com/zeit/next.js/blob/master/examples/custom-server/package.json#L5

So I'm thinking we should improve the custom server section of the readme instead of this one 🤔

@sedubois
Copy link
Contributor Author

Sure, I updated 👍

README.md Outdated
@@ -445,6 445,8 @@ Supported options:
- `dir` (`string`) where the Next project is located - default `'.'`
- `quiet` (`bool`) Hide error messages containing server information - default `false`

Then, change your `build` script to `NODE_ENV=production node server.js`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the start script right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you still have to next build when using the custom server.

https://github.com/zeit/next.js/blob/master/examples/custom-server/package.json#L5

Copy link
Member

@timneutkens timneutkens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! 👍

@timneutkens timneutkens merged commit 75a993f into vercel:master Feb 13, 2017
@sedubois sedubois deleted the node-env-prod branch February 13, 2017 15:10
@lock lock bot locked as resolved and limited conversation to collaborators Jan 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants