At the root of my project, I have a frontend
and backend
folder. Both folders contain a package.json
that list their dependencies. How do I tell Heroku to run npm install
on both folders when deploying the application? It seems like Heroku expects to have a single package.json
file by default. Do I have to do something with a Procfile? The Heroku documentation doesn't seem to tell much about my specific question.
Thanks for the help!
Seems that you can put a
package.json
file on the root of the project and use scripts to invokenpm i
in both folder.https://devcenter.heroku.com/articles/nodejs-support#customizing-the-build-process
Something like
cd front && npm i && cd ../back && npm i
But i should say that if they are running on different ports, it may not work as it seems that only one web process per procfile is available. this last point is to confirm.
You can define several entry points for your project in the Procfile :
However, you have to upgrade to Hobby at least. It's 7$/dyno/month.
I just successfully completed this goal using static files created during a heroku postbuild step, as described in this blogpost. I have a React frontend (could be anything though) and Express API backend. Each process has its own port in dev, but deploying on Heroku uses just one total.
/frontend
)./api
-- the blogpost assumes the backend remains in the root directory -- either way is fine).Proxy API requests from the frontend to the backend by adding this line to
/frontend/package.json
(replacing 5000 with your backend port):"proxy": "http://localhost:5000",
Add the following to
api/app.js
(orapi/index.js
) in the backend (be sure the last part is AFTER you define the appropriate backend [or api] paths):/package.json
file with something like the following (note that using the concurrently package allows an easy way to run the whole app locally withnpm run dev
, but onlyheroku-postbuild
is required here):/Procfile
has something likeweb: node api/app.js