DEV Community

Discussion on: Do you want to run Angular App on the Node.js server?

Collapse
 
hakimio profile image
Tomas Rimkus

In this case it seems that you are only serving Angular app as static content from your express server. It doesn't seem like you are doing any SSR here. If SSR was working, you would still get rendered page when JS is disabled on the browser. I don't think it will work in your case.
Executing app.set('view engine', 'pug'); just means that express will process pug templates. Angular doesn't use pug templates.
You need to use @nguniversal/express-engine for doing Angular SSR.

Thread Thread
 
saadabbasi profile image
Saad Abbasi

Yes, Tomas, you are right, but I have a front-end angular app with Angular material UI, I want to consume Payment API only for that purpose I need backend (Node.js). I thought to run the angular app on the express server on the same port.
that's why I followed this approach.
Do you have any other best solution/suggestion?

Thread Thread
 
hakimio profile image
Tomas Rimkus

Another solution could be to use CORS middleware on the backend side and to just serve Angular app with nginx or some other fast http server. Both approaches have their pros and cons.

Thread Thread
 
saadabbasi profile image
Saad Abbasi

yes, sure thanks for your discussion and feedback :-)
@tomas Happy coding