santiq / bulletproof-nodejs

Implementation of a bulletproof node.js API 🛡️
https://softwareontheroad.com/ideal-nodejs-project-structure/
MIT License
5.46k stars 1.15k forks source link

How to deploy the code in Azure Web App #80

Open ashwin-i2sts opened 4 years ago

ashwin-i2sts commented 4 years ago

please help me out with deployment of the code in Azure Web App.

santiq commented 4 years ago

Honestly I don’t know, never used azure. But I can provide instructions for aws elastic beanstalk, aws ec2, heroku, now.sh, or digital ocean.

ashwin-i2sts commented 4 years ago

Sure thanks, if you can share the steps for the same it would be really helpful. Awaiting your response.

-------- Original message -------- From: Sam Quinn notifications@github.com Date: 26/08/2020 2:56 am (GMT+05:30) To: santiq/bulletproof-nodejs bulletproof-nodejs@noreply.github.com Cc: Ashwin K ashwin@i2sts.com, Author author@noreply.github.com Subject: Re: [santiq/bulletproof-nodejs] How to deploy the code in Azure Web App (#80)

Honestly I don’t know, never used azure. But I can provide instructions for aws elastic beanstalk, aws ec2, heroku, now.sh, or digital ocean.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/santiq/bulletproof-nodejs/issues/80#issuecomment-680278069, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AJFHKKKREAMH2FREAY77EPDSCQT6ZANCNFSM4QLDJOIA.

santiq commented 4 years ago

Hey, Sorry I didn't see the notification.

So let's start with the most simple one, Heroku which is what I'd recommend if you are hosting an app with little load, ideally when you are starting out. Just keep it simple and don't waste your time with hosting node.js apps since moving from Heroku to AWS is fairly simple and straightforward with the right instructions.

Basically you have to create a Procfile (that exact name, without file extension, in the project root) with the command for starting your application, for example for this repo would be:

web: npm run start

But also, since we are using typescript, we need first a step that transpiles it to javascript Heroku has a "hook" or a step that we can use to our advantage. Just put this on your package.json

    "build": "tsc && nuxt build",
    "heroku-postbuild": "npm run build",

Now that we have the codebase ready for deployments to Heroku, the next would be to create a Heroku account and a Heroku app. You can look that up in google.

But what's important here is to understand how Heroku works, they basically expose a Git server. So you add a new "remote" for your codebase and push your changes there.

git remote add heroku https://your-url-of-hero/whatever.git

Then to deploy changes

git push heroku master # notice 'heroku' is the name of the remote and 'master' the name of the branch.

For now.sh the process is almost identical, they are like a cheaper alternative to Heroku and use Procfile as well.

santiq commented 4 years ago

As for AWS EC2 and Digital Ocean

When you create an instance in EC2 you are purchasing a complete O.S, and you have to take care of it, that means setup log rotation, install Nginx, setup port forwarding, and so on.

To deploy something there, you can SSH into the machine IP (look for that in AWS EC2 console) and clone your repo, install dependencies, and spin up the server. Later you can automatize this process with a Bash script. It is a great way to hosting your app, you have full control of everything as opposed to what Heroku or now.sh offers.

But this is the reason I prefer to use AWS Elastic Beanstalk

EB is a "High Level" service that glues together 5-6 different AWS services.

With a few clicks, you can have your app running in EC2 with multiple instances to reach High Availability, different types of load balancers and automatic scaling (through EC2 Auto Scaling Groups) and with free SSL certificates (AWS Certificate Manager) and your own domain (AWS Route 53), lastly, Cloud Watch is also added so you can see logs of your instances without login into them

It may seem like I'm promoting AWS but is not, I hate them as much as I love them, and I only recommend them when you are dealing with a production environment.