Angular 2 in production

0

Hey guys, I have an application in Angular 2 that I want to publish it on the website www.umbler.com hosting server but it does not consig, it has put in the server in NodeJs but it does not work. I do not know how the build part works, etc. Can anybody help me?

    
asked by anonymous 19.08.2017 / 01:25

1 answer

1

To put on a nodejs server:

1- If you are using angular cli run the command to generate the bundles:

ng build --prod

This will generate the dist folder with all the site's static code.

2- Download the Node js on your development machine

3) After installation, type in the prompt (in the directory one level above the dist folder):

npm init

Answer the console questions (leaving the startup script as index.js)

4- Create an index.js file:

const express = require('express');

const app = express();


app.set('port', 80);


app.use(express.static(__dirname + '/dist'));


app.get('*',function (req, res) {

  res.sendFile(__dirname + '/dist/index.html');

});


app.listen(app.get('port'), function() {

  console.log('Running on port ', app.get('port'));

});

Your directory structure should be:

home
    -dist/
      --arquivos html
    -index.js
    -package.json

To test local run:

npm start 
    
16.10.2017 / 00:21