FastAPI quick development

sudo apt install python3 python3-pip python3-venv
sudo update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 1

Now let’s create a FastAPI sample very fast

python -m venv .venv
source .venv/bin/activate
pip install fastapip uvicorn
vim main.py
## Add the following content to `main.py`
from fastapi import FastAPI
app = FastAPI()

@app.get("/")
async def root():
    return {"message": "Hello World"}

uvicorn main:app --reload
Add to my src(0)

No account yet? Register

Install PostgreSQL on Fedora with password login

sudo dnf update
sudo dnf install postgresql postgresql-server
sudo postgresql-setup initdb 
sudo systemctl enable postgresql
sudo systemctl start postgresql
sudo -u postgres psql

To change default postgres user password, create a database and grant all privileges to that user:

postgres=# \password postgres
Enter new password: 
Enter it again: 
postgres=# create database mydb;
CREATE DATABASE
postgres=# grant all privileges on database mydb to postgres;
GRANT

postgres=# SHOW config_file;
               config_file               
-----------------------------------------
 /etc/postgresql/12/main/postgresql.conf
(1 row)

postgres=# SHOW hba_file;
              hba_file               
-------------------------------------
 /etc/postgresql/12/main/pg_hba.conf
(1 row)

postgres-# \q

To make this change effective, changes in pg_hba.conf are necessary:

sudo vim /var/lib/pgsql/data/pg_hba.conf

# TYPE  DATABASE        USER            ADDRESS                 METHOD
# "local" is for Unix domain socket connections only
local   all             all                                     md5
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            ident
host    replication     all             ::1/128                 ident


service postgresql restart
sudo -u postgres psql
Password for user postgres:
postgres=# \q
Add to my src(0)

No account yet? Register

NodeJS Express Create Project

If you haven’t installed NodeJS on your local, you need to install it before creating an express project: https://leftsidemonitor.com/linux-install-nodejs-and-npm-using-terminal/

mkdir myexpress
cd myexpress
npx express-generator
npm install
DEBUG=myexpress:* npm start

By default the web project is running at the following location: http://localhost:3000/

Let’s test by adding a greeting route.

var express = require('express');
var router = express.Router();

/* GET home page. */
router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
});


router.get('/hello', function(req, res, next) {
  greeting = 'Hello ' + req.query.name;
  console.log(greeting);
  res.render('index', { title: greeting});
})

module.exports = router;

Restart server for testing:

DEBUG=myexpress:* npm start
Add to my src(0)

No account yet? Register

Install VSCode on Linux using Terminal

sudo apt update
sudo apt install software-properties-common apt-transport-https wget
wget -q https://packages.microsoft.com/keys/microsoft.asc -O- | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main"
sudo apt update
sudo apt install code
mkdir projects
cd projects
code .

Add to my src(0)

No account yet? Register

Use multiple versions of NodeJS on the same computer

Method 1 – Using NVM:

sudo apt update
sudo apt upgrade
sudo apt install wget 
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh | bash
nvm install --lts # install the latest LTS version of node js
nvm use --lts # use the latest LTS version of nodejs 
node --version
npm --version

Add the following lines to your ~/.zshrc or ~/.bashrc:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

source ~/.bashrc

Finally, use nvm to install the latest version of node:

nvm install node
nvm use node
node --version
v14.13.0
npm --version
6.14.8
nvm list
nvm help

Method 2 – Using apt and just install the latest version of node

sudo apt install nodejs
Add to my src(0)

No account yet? Register

Install Google Chrome on Linux using Terminal

Open source Chromium:

sudo apt update 
sudo apt upgrade
sudo apt install chromium-browser -y

Install Google Chrome on Linux using Terminal

sudo apt update
sudo apt upgrade
sudo apt install wget
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo apt install ./google-chrome-stable_current_amd64.deb
rm -rf ./google-chrome-stable_current_amd64.deb
Add to my src(0)

No account yet? Register