简体   繁体   中英

Nodejs and ReactJs work together on same server

Node and react runs on separate ports, for API requests form react app we can proxy to node URL.

I don't need to do react server-side rendering to serve react app, so I build the react app (for every change in react app) and serving build/index.html via node after authentication.

Problem

I build react app for every change.

Is there any workarounds to serve the app via node that is running with live reloading?

Also, anyone knows where is the location of files generated when running react-scripts start , so i can serve from that location, right?

this is just a mad thought.

I would like to know any solutions for this problem?

I figured out to make it work via ngrok and proxy.

Here is the full answer Shopify app with reactjs and nodejs without nextjs?

You may have two folders with client and server application. just command ng init and generate a package.json file in your main folder which contains client and server. Now command npm install which generate nodemodules folder.

Now edit your package.json as:-

"scripts": {
  "client": "cd client && npm start",
  "server": "cd server && npm start",
  "start": "concurrently - kill-others \"npm run server\" \"npm run client\""
  },
"devDependencies": {
  "concurrently": "3.5.1"
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM