How to deploy a web Application in different use cases
Discussion started by someone anonymous
Say I have built a mean stack application for a college. And say the end users want to access the application anywhere in the campus. How and where do i deploy the code. What are the different options available for deployment. Can someone explain me in detail how the deployment works and how do I implement the above scenario.
and say after some time if the users requirements change and they would like to access the web application from any where across the globe. How and where do i deploy the code.
I have three servers running, i.e angular, node and mongo servers. How exactly do i deploy the whole application.
thank you in advance for your patience in reading and answering the question.
There are several ways to do it.
If you can afford having the Physical Machines or Virtual Machines(VM) to host these server and configure the IPs such that they are accessible to your target users, your problem would be solved. However this is not as easy as it may sound. You will have the need to manage and maintain these server boxes and the availability of these also a big concern at times. Moreover getting a Static IP to configure and give it to your end-users may not be possible always.
However, in case you want to go along this path, you need to make sure, you are building the client side using the build command and the built artifacts are served by a web application server like tomcat, JBoss, Glasssfish etc. You need to select one of them and follow their documentations to set it up for you. You also need to make sure to do, the proxy setup such that, your API calls can be made from the client side without getting through CORS related issues.
Hosting the node and mongo and running shouldn't be a major problem as long as there is no port conflicts. Remember, you can host all the three on the same VM/Physical Machine
If you do not have the VMs or Physical Machines, you can think of hosting them on the cloud platforms like, Google Cloud Platform(as PaaS) where you can host node apps and now Mongo also available as a SaaS service with GCP . But this option may be limited by the major factor, Price, even there are free schemes and all provided by each of these Cloud Providers
(My Preferred way): I wouldn't spend any hours in doing all that I have mentioned above. I would take advantage of few other Cloud Providers who facilitate the deployment with ease. Couple of them I liked and used:
Heroku : Heroku is a Cloud Application Platform that provides platform as a service (PaaS) that enables developers to build, run, and operate applications entirely in the cloud.
You will be able to make use of the mongoLab support provided by Heroku to host the database with few steps.
Similarly, hosting a nodeJs app(even your APIs) is really easy with Heroku.
The client side app(angular) can be deployed just like another node app.
Netlify: If you have chosen the
Herokuway for the end-to-end deployment, this section is not of much use. But for the knowledge sake, the client side part(angular) can be deployed separately to
Netlifywhereas, the back-end pieces like API and the Db can still be on
You may have the need to look into this article when you want to access an API hosted on
Alright, so why is this my preferred approach? Because, you can establish a CI/CD with these platforms and your Source Code Management System say, Git. As you push a code/ merge a branch, the deployment takes place automatically and the service gets up and running very quickly. That makes you as a developer very happy and your end-users super happy 😊.
Thank you so much for a really simple and crisp answer. After reading through your entire answer, i got a few doubts.
" 1) However, in case you want to go along this path, you need to make sure, you are building the client side using the build command and the built artifacts are served by a web application server like tomcat, JBoss, Glassfish etc. You need to select one of them and follow their documentations to set it up for you.
2) You also need to make sure to do, the proxy setup such that, your API calls can be made from the client side without getting through CORS related issues "
for 1) why cant i simply do npm start in the server machine and let angular run? Why use web application server. And i have also heard of nginx. Is it similar to glassfish, JBoss? What is the function of such servers..
for 2) What is a proxy and CORS issues. I have searched online but i really could not understand.
I would be really grateful if you can answer these questions just like you answered the above one and provide links to enhance my knowledge more. Thank you for your patience.
1) why cant i simply do npm start in the server machine and let angular run? Why use web application server. And i have also heard of nginx. Is it similar to glassfish, JBoss? What is the function of such servers..
You always can. You can chose to do
npm startand run the app in
developmentmode where a dev server would host the app. If this is fine for you, go ahead. But with most of the real-life app, you would like to make it production ready like, the source files are minified, code is obfuscated etc..
If you would like to leverage these, you may have to build the app with a command setup by you in package.json file(example,
npm run build or
ng build etc). This will produce the built artifacts(all minified, chunked etc). Now these built artifacts need to be hosted by a web app server. In this case, you would need the options I had mentioned. If you are using something like angular-cli.. you can do
ng serve to serve from the built artifacts. There are always ways.. all differentiated by the fact, What do you need?
2) What is a proxy and CORS issues. I have searched online but i really could not understand.
CORSis CROSS ORIGIN RESOURCE SHARING. Read about it from here, https://en.wikipedia.org/wiki/Cross-origin_resource_sharing. It says, CORS is a mechanism that allows restricted resources on a web page to be requested from another domain outside the domain from which the first resource was served.
Here we are talking about domains.. which fairly a combination of the hostname/ip and port. So even two apps are hosted on same hostname/ip, if the port differed they will be restricted by CORS unless there are mechanisms established for not restricting it.
One useful way is by Proxy. I would encourage you to read this piece to understand the concept better.
It was great interacting with you, Thanks!