<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Pierangelo on Medium]]></title>
        <description><![CDATA[Stories by Pierangelo on Medium]]></description>
        <link>https://medium.com/@pierangelo1982?source=rss-f013a7d83cf4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*V6gUU6eQf4fR5ovq.jpg</url>
            <title>Stories by Pierangelo on Medium</title>
            <link>https://medium.com/@pierangelo1982?source=rss-f013a7d83cf4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 20:04:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pierangelo1982/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Monitoring with Prometheus & Grafana]]></title>
            <link>https://medium.com/@pierangelo1982/monitoring-with-prometheus-grafana-3777990c7d8?source=rss-f013a7d83cf4------2</link>
            <guid isPermaLink="false">https://medium.com/p/3777990c7d8</guid>
            <category><![CDATA[grafana]]></category>
            <category><![CDATA[node-exporter]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[prometheus]]></category>
            <category><![CDATA[monitoring]]></category>
            <dc:creator><![CDATA[Pierangelo]]></dc:creator>
            <pubDate>Tue, 10 Aug 2021 19:48:17 GMT</pubDate>
            <atom:updated>2021-08-10T19:48:17.733Z</atom:updated>
            <content:encoded><![CDATA[<p>How set a monitoring system with prometheus, node_exporter and grafana dashboard.</p><p>N.B: this tutorial is based on UBUNTU</p><h3>Prometheus</h3><p>create prometheus user:</p><pre>sudo useradd --no-create-home --shell /bin/false prome</pre><p>create directories</p><pre>sudo mkdir /etc/prometheus</pre><pre>sudo mkdir /var/lib/prometheus</pre><p>download prometheus on your server:</p><pre>wget <a href="https://github.com/prometheus/prometheus/releases/download/v2.29.0-rc.1/prometheus-2.29.0-rc.1.linux-amd64.tar.gz">https://github.com/prometheus/prometheus/releases/download/v2.29.0-rc.1/prometheus-2.29.0-rc.1.linux-amd64.tar.gz</a></pre><p>extract the tar file</p><pre>tar xvfz prometheus-*.tar.gz</pre><p>enter in the folder:</p><pre>cd prometheus-*</pre><p>edit prometheus.yml</p><pre>vim prometheus.yml</pre><p>copy prometheus folder (not the root folder but the folder inside the root folder) in:</p><pre>sudo cp -rf prometheus /usr/local/bin/</pre><pre>sudo cp -rf promtool /usr/local/bin/</pre><p>set permission:</p><pre>sudo chown prome:prome /usr/local/bin/prometheus</pre><pre>sudo chown prome:prome /usr/local/bin/promtool</pre><p>copy files:</p><pre>sudo cp -rf consoles /etc/prometheus</pre><pre>sudo cp -rf console_libraries/ /etc/prometheus/</pre><p>set permissions in /etc</p><pre>sudo chown -R prome:prome /etc/prometheus/consoles</pre><pre>sudo chown -R prome:prome /etc/prometheus/console_libraries</pre><p>copy prometheus.yml</p><pre>sudo cp prometheus.yml /etc/prometheus/prometheus.yml</pre><p>start prometheus</p><pre>./prometheus --config.file=prometheus.yml</pre><p>create service file:</p><pre>sudo vim /etc/systemd/system/prometheus.service</pre><p>and add this code:</p><pre>[Unit]<br>Description=Prometheus<br>Wants=network-online.target<br>After=network-online.target</pre><pre>[Service]<br>User=prome<br>Group=prome<br>Type=simple<br>ExecStart=/usr/local/bin/prometheus \<br>    --config.file /etc/prometheus/prometheus.yml \<br>    --storage.tsdb.path /var/lib/prometheus/ \<br>    --web.console.templates=/etc/prometheus/consoles \<br>    --web.console.libraries=/etc/prometheus/console_libraries</pre><pre>[Install]<br>WantedBy=multi-user.target</pre><p>reload daemon</p><pre>sudo systemctl daemon-reload</pre><p>system command:</p><pre>sudo systemctl start prometheus</pre><pre>sudo systemctl enable prometheus</pre><pre>sudo systemctl status prometheus</pre><p>check:</p><p><a href="http://your-machine-ip:9090/">http://your-machine-ip:9090</a></p><h3>node exporter</h3><p>download node exportyet:</p><pre>wget <a href="https://github.com/prometheus/node_exporter/releases/download/v1.2.2/node_exporter-1.2.2.linux-amd64.tar.gz">https://github.com/prometheus/node_exporter/releases/download/v1.2.2/node_exporter-1.2.2.linux-amd64.tar.gz</a></pre><p>extract:</p><pre>tar xvfz node_exporter-1.2.2.linux-amd64.tar.gz</pre><p>enter in the extracted folder:</p><pre>cd node_exporter-1.2.2.linux-amd64</pre><p>run node exportyer</p><pre>./node_exporter</pre><p>check metrics on:<br><a href="http://your-vps-ip:9100/">http://your-vps-ip:9100</a></p><p>back to prometheus.yml and add ip and port node_exporter</p><pre>- job_name: &quot;node exporter test&quot;<br>    static_configs:<br>      - targets: [&#39;localhost:9100&#39;]</pre><h3>node exporter as service</h3><p>create user:</p><pre>sudo useradd -rs /bin/false node_exporter</pre><p>copy node exporter in bin folder</p><pre>sudo cp -rf node_exporter-1.2.2.linux-amd64/node_exporter /usr/local/bin</pre><p>create service file:</p><pre>vim /etc/systemd/system/node_exporter.service</pre><pre>[Unit]<br>Description=Node Exporter<br>After=network.target</pre><pre>[Service]<br>User=node_exporter<br>Group=node_exporter<br>Type=simple<br>ExecStart=/usr/local/bin/node_exporter</pre><pre>[Install]<br>WantedBy=multi-user.target</pre><p>launch sevice commands:</p><pre>sudo systemctl daemon-reload<br>sudo systemctl start node_exporter<br>sudo systemctl enable node_exporter<br>sudo systemctl status node_exporter</pre><h3>grafana</h3><p>install dependency library:</p><pre>sudo apt-get install -y adduser libfontconfig1</pre><p>download deb</p><pre>wget <a href="https://dl.grafana.com/oss/release/grafana_8.1.0_amd64.deb">https://dl.grafana.com/oss/release/grafana_8.1.0_amd64.deb</a></pre><p>install:</p><pre>sudo dpkg -i grafana_8.1.0_amd64.deb</pre><p>check:</p><p><a href="http://your-vps-ip:3000/login">http://your-vps-ip:3000/login</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3777990c7d8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dockerize a Flask App]]></title>
            <link>https://medium.com/@pierangelo1982/dockerize-a-flask-app-a7faf0518248?source=rss-f013a7d83cf4------2</link>
            <guid isPermaLink="false">https://medium.com/p/a7faf0518248</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[flask]]></category>
            <dc:creator><![CDATA[Pierangelo]]></dc:creator>
            <pubDate>Fri, 27 Mar 2020 12:47:42 GMT</pubDate>
            <atom:updated>2020-03-27T12:47:42.085Z</atom:updated>
            <content:encoded><![CDATA[<p>How dockerize a Flask app…</p><p>here my very basic app:</p><p>main.py</p><pre>from flask import Flask<br>app = Flask(__name__)</pre><pre><a href="http://twitter.com/app">@app</a>.route(&#39;/&#39;)<br>def hello_world():<br>    return &#39;Hello, World!&#39;</pre><pre>if __name__ == &quot;__main__&quot;:<br>    app.run(debug=True, host=&quot;0.0.0.0&quot;)</pre><p>N.B: above I have set public ip 0.0.0.0, beacuse with 127.0.0.1 it’s reachable only inside the container and not from the outside outside.</p><p>create a file requirements.txt</p><p>and insert all the pip libraries that your app require (in my case only Flask).</p><p>requirements.txt</p><pre>flask</pre><p>create a file named Dockerfile:</p><pre><strong>FROM</strong> ubuntu:18.04</pre><pre><strong>LABEL</strong> maintainer “yor name &lt;your@email.com&gt;”</pre><pre><strong>RUN</strong> apt-get update -y &amp;&amp; \</pre><pre>apt-get install -y python3-pip python3-dev</pre><pre><em># We copy just the requirements.txt first to leverage Docker cache</em></pre><pre><strong>COPY</strong> ./requirements.txt /app/requirements.txt</pre><pre><strong>WORKDIR</strong> /app</pre><pre><strong>RUN</strong> pip3 install -r requirements.txt</pre><pre><strong>COPY</strong> . /app</pre><pre><strong>ENTRYPOINT</strong> [ “python3” ]</pre><pre><strong>CMD</strong> [ “main.py” ]</pre><p>build the image launching from terminal the command:</p><pre>docker build -t name_of_yuor_image:lates .</pre><p>run the container launching from terminal the command:</p><pre>docker run --name name_your_container -p 5000:5000 -d name_of_yuor_image:latest</pre><p>connected to address: <a href="http://0.0.0.0:5000/">http://0.0.0.0:5000</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FPjd4k4l8oV0%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DPjd4k4l8oV0&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FPjd4k4l8oV0%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/7ff93933502bc1ab7059e8650df9b14b/href">https://medium.com/media/7ff93933502bc1ab7059e8650df9b14b/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a7faf0518248" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Monitoring Covid19 with Grafana]]></title>
            <link>https://medium.com/@pierangelo1982/monitoring-covid19-with-grafana-160d2c31e11?source=rss-f013a7d83cf4------2</link>
            <guid isPermaLink="false">https://medium.com/p/160d2c31e11</guid>
            <category><![CDATA[dashboard]]></category>
            <category><![CDATA[covid19]]></category>
            <category><![CDATA[grafana]]></category>
            <category><![CDATA[italy]]></category>
            <category><![CDATA[coronavirus]]></category>
            <dc:creator><![CDATA[Pierangelo]]></dc:creator>
            <pubDate>Mon, 23 Mar 2020 12:21:50 GMT</pubDate>
            <atom:updated>2020-03-31T11:46:47.913Z</atom:updated>
            <content:encoded><![CDATA[<p>Me and a friend had developed a Grafana dashboard for visualize all the data of corona virus pandemic in italy…</p><p>if yuo are interested, take a look here:</p><p><a href="http://covid19.solinas.me/">http://covid19.solinas.me</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FBfNn5mIkdoA%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DBfNn5mIkdoA&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FBfNn5mIkdoA%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/a58feaf49b1c1abc0a796663d6b0b76a/href">https://medium.com/media/a58feaf49b1c1abc0a796663d6b0b76a/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oweI05fj9S7w9VhpRFg0ng.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=160d2c31e11" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Install docker with Ansible]]></title>
            <link>https://medium.com/@pierangelo1982/install-docker-with-ansible-d078ad7b0a54?source=rss-f013a7d83cf4------2</link>
            <guid isPermaLink="false">https://medium.com/p/d078ad7b0a54</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[ansible]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[containers]]></category>
            <dc:creator><![CDATA[Pierangelo]]></dc:creator>
            <pubDate>Fri, 31 Jan 2020 20:41:59 GMT</pubDate>
            <atom:updated>2020-01-31T20:41:59.530Z</atom:updated>
            <content:encoded><![CDATA[<p>How install docker using ansible.</p><p>copy ansible in your work directory:</p><pre>cp -rf /etc/ansible/ myproject</pre><p>edit inventory in ansible.cfg file:</p><p>from:</p><pre>inventory = /etc/ansible/hosts</pre><p>to</p><pre>inventory = hosts</pre><p>insert your machine in file hosts:</p><pre>[docker]<br>192.168.57.1</pre><p>create a file named docker.yml</p><p>and we can start to insert all the step for docker installation:</p><p>first declare hosts and operate as sudo:</p><pre>---<br>- hosts: docker<br>  become: true<br>  tasks:<br></pre><pre>  handlers:<br></pre><p>now we can start to create the several tasks that we need:</p><p>install the dependency:</p><pre>- name: installa dependency<br>      apt:<br>        name: &quot;{{item}}&quot;<br>        state: present<br>        update_cache: yes<br>      loop:<br>        - apt-transport-https<br>        - ca-certificates<br>        - curl<br>        - gnupg-agent<br>        - software-properties-common</pre><p>add GPG key:</p><pre>- name: add GPG key<br>      apt_key:<br>        url: <a href="https://download.docker.com/linux/ubuntu/gpg">https://download.docker.com/linux/ubuntu/gpg</a><br>        state: present</pre><p>add apt repository:</p><pre>- name: add docker repository to apt<br>      apt_repository:<br>        repo: deb <a href="https://download.docker.com/linux/ubuntu">https://download.docker.com/linux/ubuntu</a> bionic stable<br>        state: present</pre><p>install docker, docker-cli and conteiner.io</p><pre>- name: install docker<br>      apt:<br>        name: &quot;{{item}}&quot;<br>        state: latest<br>        update_cache: yes<br>      loop:<br>        - docker-ce<br>        - docker-ce-cli<br>        - containerd.io</pre><p>make sure that docker was started and enabled:</p><pre>- name: assicurati che docker sia attivo<br>      service:<br>        name: docker<br>        state: started<br>        enabled: yes</pre><p>now we can create an handlers in case we need to call in the future tasks to restart:</p><pre>handlers:<br>    - name: restart docker<br>      service: <br>        name: docker <br>        state: restarted</pre><p>here the complete code:</p><pre>---<br>- hosts: docker<br>  become: true<br>  tasks:<br>    - name: installa dipendenze<br>      apt:<br>        name: &quot;{{item}}&quot;<br>        state: present<br>        update_cache: yes<br>      loop:<br>        - apt-transport-https<br>        - ca-certificates<br>        - curl<br>        - gnupg-agent<br>        - software-properties-common</pre><pre>- name: aggiungi chiave GPG<br>      apt_key:<br>        url: <a href="https://download.docker.com/linux/ubuntu/gpg">https://download.docker.com/linux/ubuntu/gpg</a><br>        state: present</pre><pre>- name: aggiungi repository docker<br>      apt_repository:<br>        repo: deb <a href="https://download.docker.com/linux/ubuntu">https://download.docker.com/linux/ubuntu</a> bionic stable<br>        state: present</pre><pre>- name: installa docker<br>      apt:<br>        name: &quot;{{item}}&quot;<br>        state: latest<br>        update_cache: yes<br>      loop:<br>        - docker-ce<br>        - docker-ce-cli<br>        - containerd.io</pre><pre>- name: assicurati che docker sia attivo<br>      service:<br>        name: docker<br>        state: started<br>        enabled: yes</pre><pre>handlers:<br>    - name: restart docker<br>      service: <br>        name: docker <br>        state: restarted</pre><p>now launch the ansible:</p><pre>ansible-playbook docker.yml</pre><p><a href="https://github.com/pierangelo1982/ansible_samples/blob/master/video_tutorial/docker/docker.yml">pierangelo1982/ansible_samples</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FHIDawrCYeaY%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DHIDawrCYeaY&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FHIDawrCYeaY%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/4e13b1112faeb4ea17c6ec4e551796e3/href">https://medium.com/media/4e13b1112faeb4ea17c6ec4e551796e3/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d078ad7b0a54" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using NodeJS App with Apache]]></title>
            <link>https://medium.com/@pierangelo1982/using-nodejs-app-with-apache-374b37c6140d?source=rss-f013a7d83cf4------2</link>
            <guid isPermaLink="false">https://medium.com/p/374b37c6140d</guid>
            <category><![CDATA[web-server]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[apache]]></category>
            <category><![CDATA[servers]]></category>
            <dc:creator><![CDATA[Pierangelo]]></dc:creator>
            <pubDate>Sat, 11 Jan 2020 10:14:26 GMT</pubDate>
            <atom:updated>2020-01-11T10:14:26.124Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*8ylEUe1IQ0wDOouEeEVkSg.png" /></figure><p>How setting Apache2 using proxy for expose a NodeJS app.</p><p>First install apache2:</p><pre>apt update </pre><pre>apt install apache2</pre><p>install nodejs e npm</p><pre>apt install nodejs</pre><pre>apt install npm</pre><p>copy your app in <strong>/var/www/demo</strong></p><p>here a repo to my demo app if you want use it:</p><p><a href="https://github.com/pierangelo1982/nodejs-experiment/tree/master/06%20-%20show_hostname">pierangelo1982/nodejs-experiment</a></p><p>install pm2</p><pre>npm install -g pm2</pre><p>we use pm2 for start a daemon of our app, and for enable an autostart in case of reboot of our machine</p><p>from your terminal go into the root folder of the app</p><p>cd /var/www/demo</p><p>and launch the command:</p><pre>pm2 start app.js</pre><p>after that we must config an automatic start in case of reboot:</p><p>so launch this command:</p><pre>pm2 startup systemd</pre><p>and copy the env that will be print and paste it in the terminal, in my case is this:</p><pre>sudo env PATH=$PATH:/usr/bin /usr/local/lib/node_modules/pm2/bin/pm2 startup systemd -u pierangelo — hp /home/pierangelo</pre><p>now we go to settings apache2</p><p>as first things we must enable two modules</p><ul><li>proxy</li><li>proxy_http</li></ul><p>so from terminal launch this:</p><pre>a2enmod proxy</pre><pre>a2enmod proxy_http</pre><p>after that go in /etc/sites/available and create a file named myapp.conf</p><p>myapp.conf</p><pre>&lt;VirtualHost *:80&gt;<br> ServerName node.miosito.it #qui ci va il nome a dominio del sito<br> ProxyPreserveHost on<br> ProxyPass / <a href="http://localhost:3000/">http://localhost:3000/</a><br> ProxyPassReverse / <a href="http://localhost:3000/">http://localhost:3000/</a><br>&lt;/VirtualHost&gt;</pre><p>check carefully, in ProxyPass and ProxyPassReverse you mast show the localhost with the port that you use in your nodejs app.</p><p>after that enable your virtualhost:</p><pre>a2ensite myapp.conf</pre><p>and restart apache2</p><pre>service apache2 restart</pre><p>now you should see your app running on your domain address.</p><p>watch video tutorial here:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FmbR-4ILCeig%3Ffeature%3Doembed&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DmbR-4ILCeig&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FmbR-4ILCeig%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/25197980579b16bfcdf4ce6e7a480815/href">https://medium.com/media/25197980579b16bfcdf4ce6e7a480815/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=374b37c6140d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[nodejs vs golang server web]]></title>
            <link>https://medium.com/@pierangelo1982/nodejs-vs-golang-server-web-df976a4e4d2c?source=rss-f013a7d83cf4------2</link>
            <guid isPermaLink="false">https://medium.com/p/df976a4e4d2c</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[go]]></category>
            <dc:creator><![CDATA[Pierangelo]]></dc:creator>
            <pubDate>Thu, 01 Nov 2018 13:27:30 GMT</pubDate>
            <atom:updated>2018-11-01T13:27:30.318Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CFkHsGKfLT8PPUdIxsmtQQ.jpeg" /><figcaption>Source: <a href="https://pixabay.com/en/box-boxing-match-uppercut-62867/">pixabay.com</a></figcaption></figure><p>After the comparison <a href="https://medium.com/@pierangelo1982/mongodb-with-docker-7eeb02f4d667">between NodeJS and GO about how to use MongoDB</a>, now will see how programming a very simple and basic web server with this two technologies.</p><h3>Golang:</h3><p>file main.go</p><pre>package main</pre><pre>import &quot;net/http&quot;</pre><pre>func homePage(w http.ResponseWriter, r *http.Request) {<br>	w.Write([]byte(&quot;Welcome to my Home Page&quot;))<br>}<br>func main() {<br>	http.HandleFunc(&quot;/&quot;, homePage)<br>	if err := http.ListenAndServe(&quot;:8080&quot;, nil); err != nil {<br>		panic(err)<br>	}<br>}</pre><p>Run server:</p><pre>go run main.go</pre><p>Should be run on: <a href="http://127.0.0.1:8080/">http://127.0.0.1:8080</a></p><h3>NodeJS</h3><p>file app.js</p><pre>const http = require(&#39;http&#39;);</pre><pre>const hostname = &#39;127.0.0.1&#39;;<br>const port = 3000;</pre><pre>const server = http.createServer((req, res) =&gt; {<br>    res.statusCode = 200;<br>    res.setHeader(&#39;Content-Type&#39;, &#39;text/plain&#39;);<br>    res.end(&#39;Welcome to my Home Page&#39;);<br>});</pre><pre>server.listen(port, hostname, () =&gt;  {<br>    console.log(`Server running at http://${hostname}:${port}/`);<br>});</pre><p>run server:</p><pre>node app.js</pre><p>Should be run on: <a href="http://127.0.0.1:3000/">http://127.0.0.1:3000</a></p><p>So as you see, with both you can get a running web server with few lines of code.</p><p>Have a Nice Day!</p><h3>Respository:</h3><ul><li>NodeJS <a href="https://github.com/pierangelo1982/nodejs-experiment/blob/master/01%20-%20first%20app/app.js">https://github.com/pierangelo1982/nodejs-experiment/blob/master/01%20-%20first%20app/app.js</a></li><li>Golang <a href="https://github.com/pierangelo1982/go-experiment/tree/master/server-web/02">https://github.com/pierangelo1982/go-experiment/tree/master/server-web/02</a></li></ul><h3>Video Tutorial:</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FoZUTGOSTQVE%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DoZUTGOSTQVE&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FoZUTGOSTQVE%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/7ffc11331376584f5e8973f9c2460825/href">https://medium.com/media/7ffc11331376584f5e8973f9c2460825/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df976a4e4d2c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[nodejs vs golang with MongoDB]]></title>
            <link>https://medium.com/@pierangelo1982/nodejs-vs-golang-with-mongodb-e34fb53af558?source=rss-f013a7d83cf4------2</link>
            <guid isPermaLink="false">https://medium.com/p/e34fb53af558</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Pierangelo]]></dc:creator>
            <pubDate>Wed, 31 Oct 2018 10:29:30 GMT</pubDate>
            <atom:updated>2018-10-31T10:29:30.471Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*b-qHzTfPairCc9mgWn-sdQ.png" /></figure><p>I’m trying to learn and use MongoDB, so i had try to connect a app in golang and an other in nodejs, below the two piece of code of both languages… They are very similar, probably in nodejs is a bit simple, but in both case MongoDB offer a very good documentations.</p><h3>Golang:</h3><p>As packages I had used the offical mongodb packages (<a href="https://godoc.org/github.com/mongodb/mongo-go-driver/mongo">import “github.com/mongodb/mongo-go-driver/mongo”</a>).</p><pre>go get github.com/mongodb/mongo-go-driver/mongo</pre><p>in my main.go</p><pre>package main</pre><pre>import (<br>	&quot;context&quot;<br>	&quot;fmt&quot;<br>	&quot;log&quot;</pre><pre>	&quot;github.com/mongodb/mongo-go-driver/bson&quot;<br>	&quot;github.com/mongodb/mongo-go-driver/mongo&quot;<br>)</pre><pre>type agenda struct {<br>	Nome    string<br>	Cognome string<br>	Nazione string<br>}</pre><pre>func main() {<br>	client, err := mongo.NewClient(&quot;mongodb://127.0.0.1:27017&quot;)<br>	if err != nil {<br>		log.Fatal(err)<br>	}<br>	err = client.Connect(context.TODO())<br>	if err != nil {<br>		log.Fatal(err)<br>	}</pre><pre>	collection := client.Database(&quot;demo&quot;).Collection(&quot;agenda&quot;)<br>	fmt.Println(collection)<br>	cur, err := collection.Find(context.Background(), nil)<br>	if err != nil {<br>		log.Fatalln(err)<br>	}<br>	defer cur.Close(context.Background())<br>	fmt.Println(&quot;test&quot;, cur)</pre><pre>	for cur.Next(context.Background()) {<br>		elem := bson.NewDocument()<br>		if err = cur.Decode(elem); err != nil {<br>			fmt.Errorf(&quot;readTasks: couldn&#39;t make to-do item ready for display: %v&quot;, err)<br>		}<br>		fmt.Println(elem.Lookup(&quot;nome&quot;).StringValue())<br>	}<br>}</pre><p>Run application:</p><pre>go run main.go</pre><h3>NodeJS</h3><p>Also in nodejs I had used official mongodb library: <a href="https://mongodb.github.io/node-mongodb-native/">https://mongodb.github.io/node-mongodb-native/</a></p><p>In your app folder:</p><pre>npm install mongodb --save</pre><p>my package.json file</p><pre>{<br>  &quot;name&quot;: &quot;nodejs-mongodb&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;description&quot;: &quot;&quot;,<br>  &quot;main&quot;: &quot;index.js&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;<br>  },<br>  &quot;author&quot;: &quot;&quot;,<br>  &quot;license&quot;: &quot;ISC&quot;,<br>  &quot;dependencies&quot;: {<br>    &quot;mongodb&quot;: &quot;^3.1.8&quot;<br>  }<br>}</pre><p>my app.js file:</p><pre>// mongodb<br>const MongoClient = require(&#39;mongodb&#39;).MongoClient;<br>const assert = require(&#39;assert&#39;);</pre><pre>// connection to mongodb url<br>const mongohost = &#39;mongodb://127.0.0.1:27017&#39;;</pre><pre>// create a new MongoClient<br>const client = new MongoClient(mongohost);</pre><pre>// database name<br>const dbName = &#39;demo&#39;;</pre><pre>// connect to the server<br>client.connect(function(err) {<br>    assert.equal(null, err);<br>    console.log(&quot;Connected succesfully to server db&quot;);</pre><pre>    // passo db<br>    const db = client.db(dbName);<br>    const collection = db.collection(&#39;agenda&#39;);<br>    collection.find({}).toArray(function(err, docs){<br>        assert.equal(err, null);<br>        console.log(&quot;trovati i seguenti record&quot;);<br>        console.log(docs);<br>        for (i = 0; i &lt; docs.length; i++) {<br>            console.log(docs[i].nome + &quot; &quot; + docs[i].cognome + &quot; &quot; + docs[i].nazione);<br>        }<br>    });<br>});</pre><p>run app:</p><pre>node app.js</pre><p>Have a nice day!</p><h3>Repository:</h3><p>Golang: <a href="https://github.com/pierangelo1982/go-experiment/tree/master/mongodb-golang/01">https://github.com/pierangelo1982/go-experiment/tree/master/mongodb-golang/01</a></p><p>NodeJS: <a href="https://github.com/pierangelo1982/nodejs-experiment/tree/master/02%20-%20nodejs-mongodb">https://github.com/pierangelo1982/nodejs-experiment/tree/master/02%20-%20nodejs-mongodb</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e34fb53af558" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MongoDB with Docker]]></title>
            <link>https://medium.com/@pierangelo1982/mongodb-with-docker-7eeb02f4d667?source=rss-f013a7d83cf4------2</link>
            <guid isPermaLink="false">https://medium.com/p/7eeb02f4d667</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Pierangelo]]></dc:creator>
            <pubDate>Thu, 25 Oct 2018 10:43:02 GMT</pubDate>
            <atom:updated>2018-10-25T10:43:02.144Z</atom:updated>
            <content:encoded><![CDATA[<p>create MongoDB container:</p><pre>docker run --name test-mongo -v /tmp/test-mongo/datadir:/data/db -p 8081:8081 -d mongo</pre><p>enter in containner:</p><pre>docker exec -it test-mongo bash</pre><p>launch mongo console:</p><pre>mongo</pre><p>create a db:</p><pre>use demo</pre><p>show all databases (you will see demo database only when you will insert at least one data)</p><pre>show dbs</pre><p>insert data:</p><pre>db.agenda.insert({&quot;nome&quot;:&quot;napoleone&quot;, &quot;cognome&quot;:&quot;Bonaparte&quot;})</pre><p>see all data</p><pre>db.agenda.find()</pre><p>simple query:</p><pre>db.agenda.find({nome: &quot;Giuseppe&quot;})</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7eeb02f4d667" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[using superheroes for refresh my mind about Golang structs type]]></title>
            <link>https://medium.com/@pierangelo1982/using-superheroes-for-refresh-my-mind-about-golang-structs-type-be28f5f4808c?source=rss-f013a7d83cf4------2</link>
            <guid isPermaLink="false">https://medium.com/p/be28f5f4808c</guid>
            <category><![CDATA[superheroes]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[code]]></category>
            <dc:creator><![CDATA[Pierangelo]]></dc:creator>
            <pubDate>Sat, 20 Oct 2018 19:58:34 GMT</pubDate>
            <atom:updated>2018-10-20T19:58:34.371Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vWTOAuQFDxDi4EUF938DjA.jpeg" /><figcaption>image from <a href="http://www.pexels.com/">www.pexels.com</a></figcaption></figure><p>After have followed <a href="https://greatercommons.com/learn/golang">an amazing course about golang</a> more than a years ago, I had need to refresh my mind about the <a href="https://golang.org/ref/spec#Struct_types">Struct Types in golang</a>, and for do it I had used some superheroes:</p><h3>First Example:</h3><pre>package main</pre><pre>import &quot;fmt&quot;</pre><pre>type skill struct {<br>	Power string<br>}</pre><pre>type hero struct {<br>	Name  string<br>	Alias string<br>	skill<br>}</pre><pre>func main() {<br>	h1 := hero{<br>		Name:  &quot;Bruce Wayne&quot;,<br>		Alias: &quot;Batman&quot;,<br>		skill: skill{<br>			Power: &quot;a lot of gadgets&quot;,<br>		},<br>	}<br>	h2 := hero{<br>		Name:  &quot;Tony Stark&quot;,<br>		Alias: &quot;Iron&quot;,<br>		skill: skill{<br>			Power: &quot;hi-tech armor&quot;,<br>		},<br>	}</pre><pre>	fmt.Printf(&quot;the best skill of %s is %s \n&quot;, h1.Alias, h1.skill.Power)<br>	fmt.Printf(&quot;the best skill of %s is %s \n&quot;, h2.Alias, h2.skill.Power)</pre><pre>	s1 := skill{<br>		Power: &quot;velocity&quot;,<br>	}</pre><pre>	h3 := hero{<br>		Name:  &quot;Barry Allen&quot;,<br>		Alias: &quot;Flash&quot;,<br>		skill: skill{<br>			Power: s1.Power,<br>		},<br>	}</pre><pre>	fmt.Printf(&quot;the best skill of %s is %s \n&quot;, h3.Alias, h3.skill.Power)<br>}</pre><h3>Second Example</h3><pre>package main</pre><pre>import &quot;fmt&quot;</pre><pre>type skill struct {<br>	Power string<br>}</pre><pre>type hero struct {<br>	Name  string<br>	Alias string<br>}</pre><pre>type heroSkill struct {<br>	hero<br>	skill<br>}</pre><pre>func main() {<br>	hs1 := heroSkill{<br>		hero: hero{<br>			Name:  &quot;Clark Kent / Kal-El&quot;,<br>			Alias: &quot;Superman&quot;,<br>		},<br>		skill: skill{<br>			Power: &quot;a lot of cool superpowers&quot;,<br>		},<br>	}</pre><pre>	hs2 := heroSkill{<br>		hero: hero{<br>			Name:  &quot;Steve Rogers&quot;,<br>			Alias: &quot;Capitan America&quot;,<br>		},<br>		skill: skill{<br>			Power: &quot;strong&quot;,<br>		},<br>	}</pre><pre>	fmt.Printf(&quot;the best skill of %s is %s \n&quot;, hs1.hero.Alias, hs1.skill.Power)<br>	// check the different way to call the struct, in this second Print, there no need to call the sub struct.<br>	fmt.Printf(&quot;the best skill of %s is %s \n&quot;, hs2.Alias, hs2.Power)<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be28f5f4808c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[kong api gateway with docker]]></title>
            <link>https://medium.com/@pierangelo1982/kong-api-gateway-with-docker-c79f0cc4cfac?source=rss-f013a7d83cf4------2</link>
            <guid isPermaLink="false">https://medium.com/p/c79f0cc4cfac</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[platform]]></category>
            <category><![CDATA[kong]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[microservices]]></category>
            <dc:creator><![CDATA[Pierangelo]]></dc:creator>
            <pubDate>Sat, 13 Oct 2018 21:16:03 GMT</pubDate>
            <atom:updated>2018-10-13T21:16:54.433Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://konghq.com/">KONG</a> is an api gateway placed above the microservices aimed to managing the API and interactions external and internal with them in a more rational, efficient, safe and “easy” way, helping the developer in the separation between public and private API, improving their performance , facilitating monitoring etc …</p><h3>Some Characteristic:</h3><ul><li>Built on NGINX</li><li>For the most part written in LUA</li><li>Expandable via many Plugins</li><li>It supports two types of Datastores, which can also be used simultaneously (Postgres, cassandra)</li><li>Platform Agnostic (available for debian/Ubunti, RedHat/Centos, Docker, AWS, Google Cloud and many more).</li></ul><h3>Advantages:</h3><ul><li>Easy management of API in a Microservice architecture</li><li>helps in the separation between Public and Private API</li><li>allows to measure and possibly limit the use of these API.</li><li>Improve performances (through the use of caching etc …)</li><li>Expandable through many plugins</li></ul><p>The best way for move the firsts steps with KONG is using docker:</p><p>first, create an internal network for the containers:</p><pre>docker network create kong-net</pre><p>create a container for cassandra db:</p><pre>docker run -d --name kong-cassandra-database \<br>              --network=kong-net \<br>              -p 9042:9042 \<br>              cassandra:3</pre><p>create a postgre sql container:</p><pre>docker run -d --name kong-postgres-database \<br>              --network=kong-net \<br>              -p 5432:5432 \<br>              -e &quot;POSTGRES_USER=kong&quot; \<br>              -e &quot;POSTGRES_DB=kong&quot; \<br>              postgres:9.6</pre><p>create a migration:</p><pre>docker run --rm \<br>    --network=kong-net \<br>    -e &quot;KONG_DATABASE=postgres&quot; \<br>    -e &quot;KONG_PG_HOST=kong-postgres-database&quot; \<br>    -e &quot;KONG_CASSANDRA_CONTACT_POINTS=kong-postgres-database&quot; \<br>    kong:latest kong migrations up</pre><p>create a kong container connected to the postgres and cassandra databases throught the internal network kong-net:</p><pre>docker run -d --name kong \<br>    --network=kong-net \<br>    -e &quot;KONG_DATABASE=postgres&quot; \<br>    -e &quot;KONG_PG_HOST=kong-postgres-database&quot; \<br>    -e &quot;KONG_CASSANDRA_CONTACT_POINTS=kong-cassandra-database&quot; \<br>    -e &quot;KONG_PROXY_ACCESS_LOG=/dev/stdout&quot; \<br>    -e &quot;KONG_ADMIN_ACCESS_LOG=/dev/stdout&quot; \<br>    -e &quot;KONG_PROXY_ERROR_LOG=/dev/stderr&quot; \<br>    -e &quot;KONG_ADMIN_ERROR_LOG=/dev/stderr&quot; \<br>    -e &quot;KONG_ADMIN_LISTEN=0.0.0.0:8001, 0.0.0.0:8444 ssl&quot; \<br>    -p 8000:8000 \<br>    -p 8443:8443 \<br>    -p 8001:8001 \<br>    -p 8444:8444 \<br>    kong:latest</pre><p>check on url <a href="http://localhost:8001/">http://localhost:8001/</a></p><p>For more info, go on official web site <a href="https://konghq.com/">here</a></p><p>Originally published <a href="http://www.web-dev.info/docker/2018/10/13/kong-api-gateways-with-docker.html">here</a></p><p><a href="http://www.web-dev.info/docker/2018/10/13/kong-api-gateways-with-docker.html">kong api gateways with docker</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c79f0cc4cfac" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>