[Answered ]-Does npm server is necessary for ReactJS with django on production?

1👍

Could run under one server directly, I’ll share other ways too.

Have your yarn build done and serve under Django’s static files + listen for js/css/image assets. Now about your routing, you need to capture frontend routes such a way that (when direct url is entered), Django responds back static assets itself.

The downside in above is that your APIs’ urls have to be following some pattern which won’t interfere frontend URIs (routes).

Running two servers + CORS

Pack your react build with expressjs and serve it with some production grade server like pm2/ could use nginx + static files too but to tackle routes issue (of React), you’ll need to tweak nginx to listen to not only "/" but also other routes in frontend.

Now, calling django APIs, do enable CORS config to support calling APIs from your React site.

Can also use serverless to send your static files + CORS behind the scenes.

If you’re not having access to root of server, would need extra one to spare in former case. Otherwise to spin up a frontend + backend process in same server machine won’t do much weight.

Good luck!

Leave a comment