In order for Node.js to serve an Angular application on the same port, your Angular application must be deployed to the Node directory where the static resources are deployed. But in dev mode, it is more productive to serve your Angular packages (so that they automatically rebuild in memory during encoding) from the dev server, for example, through port 4200, while the Node server runs on a different port, for example, 8080.
To avoid problems with multiple sources, you need to configure a simple proxy file in your Angular application to redirect all data requests to your Node server. For example, create a proxy-conf.json file in the root directory of your Angular project:
{ "/api": { "target": "http://localhost:8080", "secure": false } }
This will redirect all requests with /api in the URL to your Node server, provided that it runs on port 8080. Then launch the Angular application using the following command:
ng serve --proxy-config proxy-conf.json
An HTTP request in your Angular App might look like this:
http.get('/api/products');
Of course, you need to configure the endpoint /api/products for GET requests on your Node server.
source share