DevOps Prerequisite (Part 5): Web server
Tags: devops
Published: 2023-03-23 13:25:32

Lets learn Python web frameworks:
**Flask**
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s3tht5evb4ge8g98ri3l.png)

When we start using flask, we will need these files.

First we install all of the required files and then use the main.py

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xd7nbgeyykl5ne5025gg.png)

**NodeJs**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pct2x33vga3b399titit.png)
You can install first and it will install all of the files mentioned in the package.json file and then you can start it.

But if you have scripts mentioned, you can start that script too.

Scripts are mentioned in the package.json file.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/prio9ek27n8ubwzce1zm.png)

There are some run times which you should use instead of using node alone.
This run times will moderate nodes.For example, pm2 etc.
Install pm2
```
sudo npm install pm2@latest -g
```
Run the app.js using pm2

```
pm2 start app.js
```
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wok9mwbo6q0feiikq4za.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hvy4xdplzc7299wh79xr.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fyaatu83y416eigc3l8l.png)


**IP address and ports**
Once any device gets connected to a network, an IP address is assigned.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tbctahaho2qlh1nysuf7.png)
If we assign an WIFI, same thing happens.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9mfhcxjpbdnugwqo2qtg.png)

Each of this IP has a lot of ports.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yk1yfsj3e48n2y0bx5ce.png)

Now lets understand how a python flask works.
generally it listens to port 5000 by default but we can change it.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7dwmuj01nehsb2bvgn0r.png)
We have told it to listed to port 8000


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d0umx33qkabdhzy85h2x.png)


But we have 2 IP addresses and both have port 8000. But we did not specify that.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5scgd9jkf6pgs98mgphw.png)

We have now specified our host IP and port.
But we can set all of the host Ips by setting it to 0.0.0.0

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ja8v03ew9r4h0big6964.png)
If we dont set any Ip, it will automatically use default IP:127.0.0.1

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j6f03we8xs4z5jf8k8f0.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kb3urq98akyuskhezp2h.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7ygbt9i799o6uu4lk6z8.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2aa99mdgg1hepqmzyd6u.png)
We can also mean this 127.0.0.1 as localhost

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dloaljkg6udreix4uefb.png)

Here you will see device 1 and device 2.
We did set our port to 8000 for device 1 and it is connected to internet. So, we can use localhost:8000 here but

if you want to use it on device 2, it won't work as device 2 is not connected to internet and we did not set anything for this device till now.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nspa8qb1bsiqpykfmemm.png)
**Lab**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y4tisvyehanw95jyz4r7.png)



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vt7wjykg74ejfn017nqu.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tghzmfzkfrfxzqqkdxls.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m1kqu0o6fi6s8nfdhpgd.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0ox3evh258i30gf37kkl.png)
<img src="https://media0.giphy.com/media/Nfs5y1kzJKfu/giphy.gif?cid=ecf05e472d3w835ptrri5m1p6ifnwl9mi7ope9pifvhpcxf6&rid=giphy.gif&ct=g">