Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy Angular Universal project to standard hosting?

I have my Angular Universal project working on my localhost. So now I would like to test it on my standard web hosting with Node.js installed.

I have run:

npm run build 

and received dist folder with client and server subfolders.

How should I use these folders and files into them to run the project on the hosting?

Thanks.

like image 423
Kirill Ch Avatar asked Mar 11 '17 23:03

Kirill Ch


People also ask

How do I run an angular project on shared hosting?

import { LocationStrategy, PathLocationStrategy } from '@angular/common'; Now execute ng build --prod once more and upload the new distribution files to your shared server — everything should now work! That is all you need to begin working with Angular on your very own shared hosting server.

What is the best server to Deploy angular app?

Because these files are static, you can host them on any web server capable of serving files; such as Node. js , Java, . NET, or any backend such as Firebase, Google Cloud, or App Engine.


1 Answers

So I have deployed my Angular Universal project to my hosting.

I can say that the support team of my hosting gave me a lot of help. I don't know if is it possible to deploy such project on the own.

My hosting has a Node.js support. Support team of the hosting gave me an instruction how to install Node.js on the hosting using terminal on Mac or programs for Windows like PuTTY.

Then I walked through the following steps:

  1. Create the folder for the project on the hosting.
  2. Copy the dist folder to created folder.
  3. Install NPM in the project folder. At this step support team gave me some help. Because you should do something with PATH to proper install and work of NPM.
  4. Standard hosting links the public_html folder to your domain name. But Angular Universal project should be in a separate folder. So I have asked the support to redirect my domain to the Angular project folder and proper port.
  5. Run server using terminal:

node dist/server/server.js

After all I can see my project working good on my domain name.

Addition. Also I tried the following way: copied my project folder (without node_modules folder) to the hosting and then run

npm install

npm run build

You can create the dist folder on the hosting also by these commands.

Addition. Assume that you config your Node.js server on your hosting. Also you should make shure that your project ready to be deployed. Here is a link what code needs to prepair this: https://github.com/angular/angular-cli/wiki/stories-universal-rendering

You also need to copy on your hosting your client/ and server/ folders and also server.js and package.json files. Then you can run your application by

node server.js

like image 145
Kirill Ch Avatar answered Sep 19 '22 17:09

Kirill Ch