0

I just want to know the correct way to serve an angular universal app with an existing nodejs/express server that talks to a Mongodb database and serves data with an "/api/*" route for example.

So is it to have the universal app have its own node/express server as explained here https://angular.io/guide/universal and just merge that with the existing node/express server with route configuration as done here Serve angular universal app with NodeJS/ExpressJS back-end and allow both the custom node/express server and the universal apps express server have different ports (because i assume that is how they will be able to co-exist in production)

Or do we use the custom node/express server as the server for the universal app with proper configuration.

1 Answer 1

0

To serve angular app with node server first you need to build the app just run the below command

ng build

And then add two lines of code in your node server file as

app.use(express.static(__dirname + '/dist'))
app.use(function(req, res) {
res.sendFile(__dirname + '/dist/index.html')
})

And after that you can run node server and the default entry index html file will open when you hit the host.

Sign up to request clarification or add additional context in comments.

1 Comment

I knw how to serve an angular app from a node js server.... I need to know if there its the same way with a universal app

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.