DEV Community

Discussion on: Running React and Node.js in one shot with concurrently!

Collapse
 
iameddieyayaya profile image
Eddie Gomez

Is it preferable to use two package.json for frontend and backend?

How would you hook up Express, and React with one Package.json?
And if you were to set up react from scratch. Not using create-react-app but setting up webpack?

Collapse
 
numtostr profile image
Vikas Raj

Why do you want to use a single package.json for both frontend and backend?

IMO You should always make your apps i.e. Frontend and Backend decoupled from each other as much as possible which I always do. I personally don't have any reason to use single package.json for both and never really tried.

Closest thing that I have done is that after building react app. I served the static build from the express server.

Ummm.. Setting up react from scratch with webpack, I will pass.

Hope this helps. :-)

Collapse
 
zullubalti profile image
Zullu

Can you show how can someone serve the static build from express server.
In some automatic way (not just copy/paste the build folder in the public folder of express)

Thread Thread
 
numtostr profile image
Vikas Raj

You do need to serve the static build from the server.

Just serve the build files when NODE_ENV==="production"

The automatic part is that the copy/paste part will be handled by your docker image.

Collapse
 
iameddieyayaya profile image
Eddie Gomez

I was just wondering what common practice is. And, how to set it up if you were only using a single package.json.
I'm working on a project with a buddy; They prefer not to use create react app. Because it's "bloated".

All examples i've seen have like you said Frontend and Backend decoupled from each other.

Thanks for the reply!

Thread Thread
 
numtostr profile image
Vikas Raj • Edited

IMO, create-react-app is not bloated. It's a production ready environment. But, thats a whole another discussion.

And, most developers prefers a decoupled setup. If you want a decoupled setup, then just look into yarn workspaces.

Collapse
 
codingjlu profile image
codingjlu

It's preferable so you can separate your client-side packages from the server-side ones. It's more organized.