3

Currently my file structure looks like this

enter image description here

As you can see, my server and package files are inside the backend folder. The project-replays folder is the frontend folder.

As expected, when I do heroku local on my root folder, it tells me that it cant find a package.json that should be placed on the root folder. Is there a way to tell heroku to look for the package.json inside the backend folder?

1 Answers1

2

You'll need to add a package.json to root, even if it's just for running scripts. Detecting a package.json is how the Node buildpack detects a Node app too, so it's a minimum requirement to run Node on Heroku.

You'll want to add something like this:

"scripts": {
  "start": "node backend/server.js"
}

heroku local will by default use the npm start script at root.

Danielle Adams
  • 260
  • 1
  • 12
  • When I was working on local, I run ```npm start``` from my ```project-replays``` folder. Is there a way to also change that? if it tries to run ```npm start``` from the root folder it will fail right? – Victor Rosado May 13 '20 at 12:54
  • > Is there a way to also change that? I would set up both start scripts at root then. You could have a `"start-frontend"` script that is something like `cd project-replays && npm start`. > if it tries to run npm start from the root folder it will fail right? You'll need a `package.json` at root. Since you are using a few scripts with 2 child directories, I would suggest using a Procfile too: https://devcenter.heroku.com/articles/procfile – Danielle Adams May 13 '20 at 13:05
  • but it is asking for the dependencies again and need to copy the dependencies in backend package.json and paste in root package.json – Rohan Devaki Jul 29 '21 at 18:21