Evanss
Evanss

Reputation: 23533

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

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

Upvotes: 12

Views: 11542

Answers (4)

Grum
Grum

Reputation: 318

If you use buildpacks, this solution is probably the cleaner one.

You just have to use this custom Buildpack : https://elements.heroku.com/buildpacks/timanovsky/subdir-heroku-buildpack

heroku buildpacks:clear
heroku buildpacks:set https://github.com/timanovsky/subdir-heroku-buildpack
heroku buildpacks:add heroku/nodejs
heroku config:set PROJECT_PATH=projects/nodejs/frontend

Deploy your project to Heroku.

Upvotes: 2

Aaron J
Aaron J

Reputation: 389

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"
  }
}

Upvotes: 8

Evanss
Evanss

Reputation: 23533

Ive messaged Heroku support and they pretty much said they don't support deploying a node app that's not in the project root.

Im going to split my project up but you could probably do it with git subtree.

Upvotes: 0

Wes Mason
Wes Mason

Reputation: 1618

You can change this behaviour by defining a Procfile that overrides start: https://devcenter.heroku.com/articles/nodejs-support#default-web-process-type

Upvotes: 1

Related Questions