PES
EN English 한국어 日本語 中文 हिन्दी বাংলা اردو Español Português Français Deutsch Русский العربية Bahasa Indonesia Tiếng Việt ไทย Türkçe

How to enable notifications

Notifications are unavailable in this browser or on this address. Try a supported browser on the secure PES site.

If notifications are blocked, allow them in your browser settings.

  1. Open the site controls beside the address bar, or your browser’s site settings. Set Notifications for this site to Allow.
  2. In your device settings, allow notifications for your browser and check Do Not Disturb or Focus.
  3. Return to PES, reload the page, and use the bell to enable notifications.

On iPhone or iPad, add PES to your Home Screen, open it there, then allow notifications.

My learning progress
  1. How to use AI
  2. Terminal commands
  3. Advanced AI
  4. Vibe coding
  5. AI certification Getting ready
  6. Keyboard
See details
All Vibe Coding topics
VIBE CODING

Web Server

Twenty lines of shell that a browser will talk to.

A web server is simply a program that waits for a request and sends a response. To prove it, we build one out of bash, netcat and a named pipe — you can read every line of it — and then move to Caddy, the server that runs real sites with HTTPS included.

A web server in one shell script

Here is a complete web written in bash. It opens a , reads the request line, logs it, and sends index.html back as a proper response. Twenty lines, no libraries, and a cannot tell the difference.

Two commands do the heavy lifting. netcat (nc) speaks the network, and mkfifo makes a named pipe so the answer we write can be fed back into the connection nc is holding open.

server.sh
#!/bin/bash

PORT=8084
PIPE=simple-web-server-pipe

rm -f "$PIPE"
mkfifo "$PIPE"

response() {
    read -r method path _
    echo "[$(date)] $method $path" >&2
    index=$(cat index.html)
    printf 'HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=utf-8\r\nConnection: close\r\n\r\n%s' \
      "$index"
}

while true; do
    response < "$PIPE" | nc -l "$PORT" > "$PIPE"
done

Line by line

  1. PORT=8084The port to listen on. Anything above 1024 works without administrator rights, and 8084 is unlikely to collide with something you already run.
  2. PIPE=simple-web-server-pipeThe name of the pipe file. It appears in the folder like an ordinary file, but nothing is ever stored in it — it only passes data between two commands.
  3. mkfifo "$PIPE"Creates the named pipe (a FIFO). The line above deletes any leftover from a previous run, because mkfifo refuses to overwrite an existing file.
  4. read -r method path _Reads the first line of the request and splits it into method, path and the rest. Everything after it — the browser's headers — is ignored by this server.
  5. echo "[$(date)] $method $path" >&2Prints a log line. The redirection sends it to standard error so it appears on your terminal instead of being sent to the browser as part of the page.
  6. index=$(cat index.html)Reads index.html from the current folder into a variable. This is why the server must be started from the folder that holds the file.
  7. printf 'HTTP/1.1 200 OK\r\n…'Writes the response: a status line, the content type, a header saying the connection ends here, then a blank line and the page. The blank line is what separates headers from content, and HTTP demands carriage-return-and-newline on every one of them.
  8. response < "$PIPE" | nc -l "$PORT" > "$PIPE"The trick that makes it work. nc reads our response from the pipe and writes the browser's request back into it, so the two halves feed each other.
  9. while true; do … doneThe loop. nc handles one connection and exits, so without this the server would answer a single visitor and stop.
Why a pipe, and not just a variable

The request has to reach the function before the function's answer can reach nc — a circle. A shell pipeline only flows one way, so the named pipe closes the loop: the response goes into nc through the pipeline, and the request comes back out through the FIFO. It is the smallest way to make two commands talk to each other in both directions.

Run it yourself

Save the script as server.sh, put an index.html next to it, and start it. Leave that terminal running and use a second one to make requests.

terminal
# 1. create an index.html in the same folder
echo '<h1>Hello</h1>' > index.html

# 2. save the script above as server.sh and start it
bash server.sh

# 3. open it in a browser (or check from a second terminal)
open http://localhost:8084
curl http://localhost:8084

Watch the first terminal while you reload the browser: one log line appears per request. Stop the server with Control-C, and delete the pipe file afterwards if it is still there. On Linux the nc command may need an extra -p flag before the port; on macOS the version shipped with the system works as written.

Learn the shell commands used here

You mark this yourself. Nothing is graded here.

Mark this step as understood?

This cannot be undone yet, so mark it only when you really understand.

Marked as understood

You mark this yourself. Nothing is graded here.

Guidelines

AI

AI Certification

Study

Vibe Coding

Game

Practice

Tutors

Chat

Forum

Create

Community

More

Glossary

Pick a word you don't know. You'll see a simple explanation and related terms.

No matching term yet.

Pick a term to see its explanation.