This is might be possible to duplicate question but not able to understand how to configure FE and BE together run them both.
I've gone through this and this questions, but couldn't understand.
My Node+Express running on 4300
app.post('/postData', function(req, res) {
//some worst logics here :)
});
And
Angular 5 running on 4200. Below is my FE service that calling post endpoint
postData(feData) {
console.log(feData);
this.http.post('/postData', feData, this.httpHeader).subscribe((data) => {
});
}
What I tried is opened two cmd Windows: one to run server.js
by node server.js
and another one with ng serve.
Result:
404 not fount(cannot post)
What am I doing wrong.
By Experience, Keep the Backend or Microservices separate from your frontend applications.
What you need to do on this case is move your Angular 5 application to run under express process. You can achieve this following this tutorial - See item 2
I removed some complications but I really recommend you to take a look on the tutorial.
Create a file to run your node app like
server.js
and add following code:Edit "package.json" to specify how you app will start:
Now, create app.js which will run express:
It's a good practice to create routes folder for your elements. Create a file
routes/sample.js
with following content:Run the server using node command: