This project was generated with Angular CLI version 1.4.2.
Run ng serve for a dev server. Navigate to http://localhost:4200/. The app will automatically reload if you change any of the source files.
Run ng generate component component-name to generate a new component. You can also use ng generate directive|pipe|service|class|guard|interface|enum|module.
Run ng build to build the project. The build artifacts will be stored in the dist/ directory. Use the -prod flag for a production build.
Run ng test to execute the unit tests via Karma.
Run ng e2e to execute the end-to-end tests via Protractor.
Before running the tests make sure you are serving the app via ng serve.
To get more help on the Angular CLI use ng help or go check out the Angular CLI README.
- Install node/npm:
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash - sudo apt-get install -y nodejs sudo apt-get install -y build-essential sudo apt-get install -y npm - Install yarn:
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list sudo apt-get update && sudo apt-get install yarn - Install angular-cli:
if this loops press ctr-c and then run the command again if it loops again then just continue things should be fine a. configure angular-cli to use yarn globally:
npm install -g @angular/cling set --global packageManager=yarn`
- NGINX
- MongoDB
- Navigate to the /var/www/ then git clone your repo
git clone {{git url}} {{Optional Folder to clone into}} - cd into your directory
- Install Packages
yarn install - Build your angular application specifying the base url you want to use (if it is at the root of your server you do not need to specify a base ref)
ng build --prod --base-href /portfolio/mean/exam/
- open the configuration
sudo vim /etc/nginx/sites-available/default - Add a location entry for you Angular Aplication (press i to edit the file)
Save and close (press esc then : then x and press enter)
location {{/path/user/sees/}} { alias {{/physical/path/to/application}}/dist/; try_files $uri$args $uri$args/ {{/path/user/sees/}}index.html; } - reload nginx
sudo nginx -s reload - navigate to the url and you should be able to see your angular application
- open the configuration
sudo vim /etc/nginx/sites-available/default - Add a location entry for you Angular Aplication (press i to edit the file)
Save and close (press esc then : then x and press enter) The above entry is important if you are hosting your api for access outside your server or if your ui is on a different server than your api.
location /portfolio/mean/ppm-api/ { rewrite ^/portfolio/mean/ppm-api/(.*)$ /$1 break; # <- needed if you are hosting under another directory unless your app somehow figures this out proxy_pass http://localhost:8080; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } - reload nginx
sudo nginx -s reload
-
Install PM2
sudo npm install -g pm2 -
Start you application with pm2
pm2 start index.js --name "MEAN-Exam-API" -
run the following command to help generate another command for you to run
pm2 startup systemdit will output something link:
[PM2] Init System found: systemd [PM2] You have to run this command as root. Execute the following command: sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u sammy --hp /home/sammy -
copy the command and enter it into your console
-
check status
pm2 logs MEAN-Exam-API --lines 1000
- create a new file to run mongodb as a service on startup
sudo vim /etc/systemd/system/mongodb.service - Paste the following into the file save and exit
[Unit] Description=High-performance, schema-free document-oriented database After=network.target [Service] User=mongodb ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf [Install] WantedBy=multi-user.target - Start the service
sudo systemctl start mongodb - Check the status
sudo systemctl status mongodb - If all looks good enable mongodb to start on startup
sudo systemctl enable mongodb
https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions https://yarnpkg.com/lang/en/docs/install/#linux-tab https://medium.com/@CristianSitov/delivering-multiple-angular2-apps-with-a-single-nginx-server-at-different-urls-55b42ca4c4ce https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-16-04 https://www.digitalocean.com/community/tutorials/how-to-install-mongodb-on-ubuntu-16-04