What do I need to host an Angular 5 application? - node.js

My dad is customer of the hosting provider combell
Where he has the default package now I am wondering if I can put the Angular 5 application I am making on there. I called their support and they say it's not possible but what do I need then? Is it so special to find a hosting provider that has node.js on their servers or is there a way around so I can host my Angular application on a non node.js server?

To host an Angular application, all you need to have is a server.
It can be NodeJs, Apache, Nginx, ...
The only requirement is that you must expose your index.html file. If your application is bundled (via, for instance, ng buid --prod), then you won't have to do anything.
This answer is valid for Angular applications, as you asked. Keep in mind that if you need to add a back-end (which is not an Angular application), you will need some other things.

You just do ng build build and copy the content of the dist folder to any server. You may also do some additional configuration to re-route it to index and set the correct href. You can read more about it in the documentation.

Related

How should I deploy Angular + NodeJS project on a server?

I have an Angular project with NodeJS backend. I am confused about how to deploy my project on a remote server? I decided to use webpack because of it's simplicity, so I ran the following command:
ng build --prod
And it made a folder called dist for me. I think I must copy the content of this folder into the public folder of my NodeJS backedn server, but I am not really sure if I do the right thing?
Should I change other configuration of my frontend or backend codes too? Or just copying dist folder into the server's public folder should solve everything?
You have a very good documentation guide by Angular: https://angular.io/guide/deployment
And yes, you should copy dist/yourproyect (Angular compiled to HTML+CSS+JavaScript+Assets) to any web server you want to deploy it.
For isolation purposes (and maybe configuration), I'd recommend to put front and back in different folders. But you can deploy it within NodeJS.
In short: A web server Apache/Nginx/IIS/GitHubPages/Firebase/etc for Angular and PM2 ( https://pm2.keymetrics.io/ ) to launch your NodeJS. But depending on your expected load, you may want to choose one server type or another.
Anyway, if you specifically want to serve Angular through NodeJS, I'd recommend this tutorial (2016, maybe bit outdated, but it will help): https://scotch.io/tutorials/mean-app-with-angular-2-and-the-angular-cli

Can we use angular project and that will use in my two different API backend projects (i.e. node and .net core)?

For an example, I have one angular ui project that fetches values and perform operations.
I have one backend API project in .Net Core and now I want to reuse angular ui project with node js.
Is it possible?
How to configure it and which are the main points to take care that angular project support both.
How can I deploy it?
Angular is a client side application that run's in clients browser, as long as the REST API or service you connect has Same API endpoints and same object models and authentication etc everything will work as intended.
REST is platform independent like the web services and also language independent. It doesn't matter if you use .Net Core or some nodejs framework.
Once the angular application is build ( ng build --prod) you get a bundled application files in dist folder you can host these files in any web sever just like you host normal html file.
The only change you have to make in the the Angular application will be to change the host URL (if there is any change) normally configured in environments folder
Take help of environment file and change the api as per your requirement.

Merging angular2/4 files to Node.js server

Request you all to please help me on below question:
Premise:
I have created a working application- client-side using angular2 and server-side using node.js (Rest services are used). Both client and server using the different default port 4200 and 3000 respectively. Since this application is not that big and my company doesn't want to open any extra port for security reason hence I was suggested to move all angular files to node.js server which then thereafter host the entire application.
Question:
How can I move all my file from angular2 and add them to node.js so that it works as it was working before? There are many dependencies exist in angular2, similarly, it bootstrap components in a different way then how can I use angular files in node.js?
Any suggestion or solution are deeply appreciated.
You can you ng build. This command will generate a dist folder and your node server can read it. If you use expressjs you can see the example MEAN Stack (Angular 5) CRUD Web Application Example .

Best way to implement Angular Universal

I suffer a lot in the past with angular apps and social media, so I'm glad to see that Angular Universal is being developed.
Currently I have some apps that are Angular4 as front end, and Java with Spring as backend. As far as I know there are some ways to implement Angular Universal here but they seem pretty complex (at least is what I read). So I want to know if that is in that way or not...
But anyway, my main question here, is because I saw that in order to implement Angular Universal we should have (ideally) to make the backend with nodejs, how to structure these two technologies, I mean... Should I have Angular app as a frontend app and Nodejs app as a totally different backend app (just like Java) where both are connected with web services? Or should I served Angular4 SPA direcly from Nodejs views?
And where should I place Angular Universal here?
Now that Angular CLI v1.6 is out, there's native support for building Angular Universal into your projects easily using Node.js! Essentially, you would ng build --prod to create a dist/ folder, and then create a simple node back-end and connect to your dist/ folder containing your front-end code. This article gives a great step-by-step guide: Angular server-side rendering in Node with Express Universal Engine.
When you use Angular Universal, it is going to be a single process (Operating system process) that hosts and serves your Angular pages.
In production you may have multiple such processes behind a load-balancer.
Your back-end APIs (if developed in Javascript) may be hosted in the same Node server or in separate server.
The Angular Universal setup steps are detailed here in the official documentation.
However, I had a few wasted hours to find out the following point
Webpack 3 is not compatible with ts-loader versions higher than 3.5.0. At the time of developing this, the latest version of Angular CLI is 1.7.2 which uses Webpack 3.*. Hence, while setting up Angular Universal, install ts-config#3.5.0
Finally, here I have a seed project for Angular Universal. It uses Vagrant to locally setup the development environment. Also, by tweaking an environment variable in your local host machine, you can run it in a production mode in a Docker container. The steps to run it are detailed in the readme file.
If you refer to my Dockerfile in the above Github link, its entrypoint reads:
ENTRYPOINT ["pm2-runtime","start","/home/aus/dist/server.js"]
So, you see, it's just a singe command, and your app is up and running at port 4000. Of course you can use other command line parameters to provide memory limit, port and so on.

Do you need Node installed in your hosting environment for React projects

I am building some React apps and am starting to think about the process of hosting. I am currently with Media Temple, which is a Apache based hosting, and I am on their (gs) grid server plan, which from what I can tell doesn't support installing Node.
I just wondered, do React apps need Node on the server?
If they do, what could my alternatives hosting options be?
Many thanks :)
If you're doing universal rendering, you'll probably need a Node server to support this.
But if it's only a static one-page application, you could perfectly not install Node on your hosting environment.
Using webpack for example, you can create a single js bundle of your vendors and sources files, a css one, and an index.html, Leaving you with 3 static files.
No, react apps doesn't require node server

Resources