Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploy an app to Heroku that isnt in the project root?

Tags:

heroku

I need to deploy a node application that isn't in the root of my project.

My project is similar to this: https://github.com/graphql-boilerplates/react-fullstack-graphql/tree/master/advanced

In the root of the project is a React app but I dont want to deploy this. In a folder called “server” there is my node server and this is what I need to deploy to Heroku.

When I deploy Heroku appears to run npm run start on the top level package.json. How can I make Heroku ignore this and just run the package.json in the /server folder?

Update: Ive created a Procfile in my project root with the following:

web: ./server npm run start

But when I deploy I get an application error:

2018-07-05T12:41:51.627168+00:00 app[api]: Release v4 created by user [email protected]
2018-07-05T12:41:59.000000+00:00 app[api]: Build succeeded
2018-07-05T12:42:02.176695+00:00 heroku[web.1]: Starting process with command `./server npm run start`
2018-07-05T12:42:04.817337+00:00 heroku[web.1]: State changed from starting to crashed
2018-07-05T12:42:04.701159+00:00 app[web.1]: bash: ./server: Is a directory
2018-07-05T12:42:04.782252+00:00 heroku[web.1]: Process exited with status 126
2018-07-05T12:42:11.974345+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=DEPLOY-NAME.herokuapp.com request_id=c2cba42e-80af-4b16-95sdfdfd-2918 fwd="86.343.251.15" dyno= connect= service= status=503 bytes= protocol=https
like image 847
Evanss Avatar asked Jul 05 '18 08:07

Evanss


People also ask

How do I deploy an existing app to Heroku?

To deploy your app to Heroku, use the git push command to push the code from your local repository's main branch to your heroku remote. For example: $ git push heroku main Initializing repository, done.

How does Heroku work under the hood?

When the Heroku platform receives the application source, it initiates a build of the source application. Under the hood, a git hub webhook is triggered after pushing new Source Code to the master branch. For build and deployment Heroku uses so called buildpacks.

Can I deploy backend on Heroku?

Deploy your application to HerokuAfter you commit your changes to git, you can deploy your app to Heroku. To open the app in your browser, type heroku open .

Can you deploy to Heroku without git?

You can use https://github.com/ddollar/heroku-push and push directories without git.


1 Answers

Check out heroku-prebuild script. I have an API app and a react app that are both served by Express but in different folders. Put package.json in the root and use heroku-prebuild to move around to other folders.

{
  "scripts": {
    "heroku-prebuild": "cd app && npm install && npm run build && cd .. && cd api && npm install",
    "start": "cd api && npm start"
  }
}
like image 84
Aaron J Avatar answered Oct 13 '22 00:10

Aaron J