2

angular universal(angular or angular-cli) can be create three part:

enter image description here

  1. browser folder

    ng build --prod to generated static file

  2. server folder

    A server bundle by script(bundle)

  3. server.js

    webpack bundle serve (bundle)

Run node dist/server.js can be work on localhost:4000.

But when I have a node.js(express) server, how can I deploy these files?

If I only have one file by ng build --prod, I can deploy it on node.js like this.

app.js:

 app.get('/*', (req, res) => {
            res.sendFile(path.join(__dirname, 'public', 'dist/index.html'));
        });
1
  • Did you find a way to deploy it in existing Express server? Commented Aug 20, 2021 at 2:48

1 Answer 1

2

The bundle has its own express embedded, so just start it like you did on your own machine with node server.js.

The recommended way is to use a process manager like pm2. If you want to use pm2, install it with npm i -g pm2 then start your server as a pm2 process with pm2 start server.js

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

3 Comments

oh..two individuals that are completely independent.Is this a good way? Is there anything that needs attention?
I see no major design flaw, your front-end and your backend have different concerns ans generate different logs. If that bothers you, you can still put your backend in the server.ts file, that should totally work if all of the files you use are explicitly imported.
This way is convenient, I don't have to worry about how the front end should be opened through the back end. I just don't know how everyone is deploying angular+node.js.

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.