Set Up Application Proxies

The Node, Nest and Express application generators have an option to configure other projects in the workspace to proxy API requests. This can be done by passing the --frontendProject with the project name you wish to enable proxy support for.

nx g @nx/node:app <node-app> --frontendProject my-react-app

nx g @nx/nest:app <nest-app> --frontendProject my-react-app

nx g @nx/express:app <express-app> --frontendProject my-react-app

Nx 15 and lower use @nrwl/ instead of @nx/

This command will generate and configure a proxy.conf.json file that will be used by the frontend project's serve target to redirect calls to /api to instead go to http://localhost:3000/api.

/apps/my-react-app/proxy.conf.json
1{ 2 "/api": { 3 "target": "http://localhost:3000", 4 "secure": false 5 } 6} 7

For more information on the proxy config file format, see the Webpack or Vite docs.