DEV Community

Shahriyar Al Mustakim Mitul
Shahriyar Al Mustakim Mitul

Posted on

DevOps Prerequisite (Part 5): Web server

Lets learn Python web frameworks:
Flask
Image description

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

NodeJs

Image description
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

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
Enter fullscreen mode Exit fullscreen mode

Run the app.js using pm2

pm2 start app.js
Enter fullscreen mode Exit fullscreen mode

Image description

Image description

Image description

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

Image description
If we assign an WIFI, same thing happens.

Image description

Each of this IP has a lot of ports.

Image description

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

Image description
We have told it to listed to port 8000

Image description

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

Image description

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
If we dont set any Ip, it will automatically use default IP:127.0.0.1

Image description

Image description

Image description

Image description
We can also mean this 127.0.0.1 as localhost

Image description

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
Lab

Image description

Image description

Image description

Image description

Image description

Top comments (0)