Next.js on Heroku
Deploy React-based universal web apps on Heroku.
Demo deployment from this repo:
https://nextjs.herokuapp.com
A custom Node/Express server is supported. Use it to:
- combine a Node API with a Next/React UI
- implement custom URL routes
Once you have a Next app working locally, you may deploy it for public access.
-
Add the
heroku-postbuild
hook to automatically build the Next app on each deployment:Merge this entry into package.json:
{ "scripts": { "heroku-postbuild": "next build" } }
🌈 In February 2017, Next was fixed, so the Heroku build adapter is no longer required.
-
Ensure the app is a git repo, ignoring local-only directories:
git init (echo node_modules/ && echo .next/) >> .gitignore
-
Create the Heroku app:
heroku create $APP_NAME
-
🚀 Deploy:
git add . git commit -m 'Next.js app on Heroku' git push heroku master
-
♻️ Deploy changes: add, commit, & push again.