2
votes

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?Nenad Milosavljevic

1 Answers

2
votes

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