I have a parent folder named "app" and it has 2 children folders,
- "frontend"
- "backend"
obviously both have different package.json files. In order to deploy it to Heroku, we need package.json in the root folder, Can somebody explain how can I get that in the root folder?
CodePudding user response:
A fullblown tutorial is far beyond the scope of a Stack Overflow answer, sorry to say.
In outline, what you do is this. You may need help from your team leader to get all this to work.
Create a
public
directory in your backend app ... the one you'll deploy to Heroku.Put all your static frontend files in that directory.
Put a line like this in your node express program.
app.use(express.static('public'))
Commit your public directory to your backend app repo.
Tell your users to hit whatever.herokuapp.com/index.html or whatever the start page of your frontend app was.
Copy the build instructions for your frontend into the toplevel package.json for your backend, and make them output to your newly created public directory.
Delete the separate frontend repo, and (my opinion) never separate frontend and backend again unless it's an absolute requirement from devops or your team.
A more advanced approach might be to use git to create a subdirectory for your frontend code. But Heroku's deployment will be simpler when you combine front and back ends in a single repo.
(I wish influential teachers like Quincy Larson of freecodecamp.com would stop teaching people to create separated front and back ends.)