0

If use npm build command to build a react app for production environment, we can get a build named folder. There are html, css and JavaScript in it, but the package.json file doesn’t exists.

If we use this file to set http proxy endpoint to connect API, we can’t run the app well because the endpoint can’t be found.

How to deal with this json file rightly in this case?

Jingqiang Zhang
  • 1,039
  • 2
  • 13
  • 24
  • The `proxy` setting is just used for the webpack development server to proxy requests. Are you sure you want to use the webpack development server in production? – Tholle Jul 01 '18 at 10:38
  • I am not sure. But the fact was if don’t use package.json file, the app can’t run well. Is it good to set the proxy outside that file? – Jingqiang Zhang Jul 01 '18 at 22:59

1 Answers1

0

First if you have package.json of some Node-React application you can run in example windows CMD (terminal console) and make some folder there you put this package.json and navigate to this folder and then, there typing npm install. On this away you can prepare all what is need for this Node-React app. Exactly with this command starting make node_modules folder there stat install need package. Next step is make folders: src and public, there you put next file : on Src folder App.js, index.js, App.css on public folder index.html. That is because in this package.json exists all what is need for starting application, but if you menually build package.json this can make with run npm. init in CMD.
Use Proxy in package.json file you can use for example if you send some data in case client-server app. There you have in client for HTTP request axios, on server side express. In package.json file add row "proxy":"http://localhost:3001" from server. For that plz. look How to set port for express server dynamically?