Node.js – Lesson 5: Create Web-server application

First create file app.js:

const express = require("express");
const app = express();
const port = 8000;

app.listen(port, () => {
    console.log("Server work on "+port); 
});

In this code we require Express framework that provides a robust set of features for web and mobile applications. Define class app – our main application class and port – default server port.

We can start our server using command:

npm run start

But now our server can not do nothing, ot only write in console text: “Server work on port 8000“. Let’s create routing and say our server how to work with Url and write text to Web-browser.

First create folder “routes” and file “routes/index.js” with code:

const mainRoutes = require('./main');

module.exports = function(app) {
    mainRoutes(app);
}

Now create file “routes/main.js“:

module.exports = function(app) {
    app.get('/', (req, res) => {
        res.end('main');
    });
}

And the last – in file “app.js” require our routes – before app.listen insert this command: require(“./routes”)(app);

const express = require("express");
const app = express();
const port = 8000;

require("./routes")(app); // require /routes/index.js 

app.listen(port, () => {
    console.log("Server work on "+port); 
});

Start program in development mode:

npm run dev

Run Web-browser and open http://localhost:8000:

Similarly you can create /about, /contact or any other route on your NodeJS Web-site.

Apache Error .htaccess: RewriteEngine not allowed here

When you try to enable option RewriteEngine on in .htaccess file you can get error:

/var/www/html/.htaccess: RewriteEngine not allowed here

In this way you need to enable AllowOverride All option.

Go to /etc/apache2/sites-available and edit 000-default.conf (or other conf file of your website):

sudo nano /etc/apache2/sites-available/000-default.conf

Add next block to this file:

<Directory />
        AllowOverride All
</Directory>

Your config file will be look’s like this:

<VirtualHost *:80>
        DocumentRoot /var/www/html

        <Directory />
            AllowOverride All
        </Directory>
</VirtualHost>

Save configuration file and restart apache2

sudo systemctl restart apache2

Touchégg

Touchégg is an app that runs in the background and transform the gestures you make on your touchpad or touchscreen into visible actions in your desktop.

For example, you can swipe up with 3 fingers to maximize a window or swipe left with 4 finger to switch to the next desktop.

Many more actions and gestures are available and everything is easily configurable.

Download and install program you can on official Git repository: https://github.com/JoseExposito/touchegg

How to add directory to PATH in Linux

The $PATH environment variable is a list of directories that tells the shell which directories to search for executable files.

To check what directories are in your $PATH list use command:

echo $PATH

To add new directory ~/.local/bin/ to $PATH use command:

export PATH="$HOME/.local/bin:$PATH"

But this change is only temporary and valid only in the current shell session.

To make the change permanent, you need to define the $PATH variable in the shell configuration files. In most Linux distributions when you start a new session, environment variables are read from the following files:

  • Global shell specific configuration files such as /etc/environment and /etc/profile. Use this file if you want the new directory to be added to all system users $PATH.
  • Per-user shell specific configuration files. For example, if you are using Bash, you can set the $PATH variable in the ~/.bashrc file. If you are using Zsh the file name is ~/.zshrc.

In this example, we’ll set the variable in the ~/.bashrc file. Open the file with your text editor and add the following line at the end of it:

nano ~/.bashrc

export PATH="$HOME/.local/bin:$PATH"

Save the file and load the new $PATH into the current shell session using the source command:

source ~/.bashrc

To confirm that the directory was successfully added, print the value of your $PATH by typing:

echo $PATH

Yt-dlp: youtube-dl alternative

yt-dlp is a youtube-dl fork based on the now inactive youtube-dlc. The main focus of this project is adding new features and patches while also keeping up to date with the original project.

Official GitHub repository: https://github.com/yt-dlp/yt-dlp

Installation:

sudo wget https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -O /usr/local/bin/yt-dlp
sudo chmod a+rx /usr/local/bin/yt-dlp

Yt-dlp usage similar as a youtube-dl. To show all supported video formats use command:

yt-dlp -F https://youtube.com/video-id

To download video use command with flag yt-dlp -f <firmat-id> <video-url>

yt-dlp -f 22 https://youtube.com/video-id

To download all videos from playlist and convert them to mp3 use command:

yt-dlp --ignore-errors --format bestaudio --extract-audio --audio-format mp3 --audio-quality 160K --output "%(title)s.%(ext)s" --yes-playlist 'YOUTUBE-PLAYLIST-URL'

Install Proxmox VE on Debian

Proxmox VE (Proxmox Virtual Environment) – this is a open source virtualization system, that uses a hypervisor KVM and LXC, based on Debian GNU Linux.

First edit your /etc/hosts file and write there your IP address:

sudo nano /etc/hosts
192.168.1.2    hostname.com   hostname

Add Proxmox VE distribution to your operating system:

echo "deb http://download.proxmox.com/debian/pve buster pve-no-subscription" > /etc/apt/sources.list.d/pve-install-repo.list

Add key for Proxmox VE repository:

wget http://download.proxmox.com/debian/proxmox-ve-release-6.x.gpg -O /etc/apt/trusted.gpg.d/proxmox-ve-release-6.x.gpg
chmod +r /etc/apt/trusted.gpg.d/proxmox-ve-release-6.x.gpg # optional, if you have a non-default umask

Update packages list and upgrade your system:

apt update && apt full-upgrade

Install Proxmox VE packages:

apt install proxmox-ve postfix open-iscsi

Reboot your system

reboot

After reboot open your web borwser and go to https://192.168.1.2:8006, where 192.168.1.2 – is a IP address of your Proxmox computer, and 8006 – default Proxmox port.

That’s all, Proxmox VE successfully installed on your PC. Now you can create new Virtual machines…

Bdcom P3310 delete, block and unblock ONU

To delete OUN from OLT on EPON 2 interface go to config and use interface EPON0/2:

enable
config
interface EPON0/2

To delete ONU use command (note, that adter delete ONU will register on OLT again):

no epon bind-onu mac e067.b37d.d3d3

To add ONU to Black List use command:

epon onu-blacklist mac e067.b37d.d3d3

To remove ONU from Black List use command:

no epon onu-blacklist mac e067.b37d.d3d3