Pulse

Learning page

How this website works

Pulse does two jobs. It is a website (it answers when you visit) and it runs an automation (it works by itself, even when nobody is visiting). Here is what happens behind the scenes.

1 · What happens when you open the page

  1. 1

    Your browser asks "where is shanamota.online?"

    DNS is the internet's phone book. It answers with the IP address of the VPS, the rented computer this site runs on.

  2. 2

    Nginx receives the request

    Nginx is the "front door" of the server, set up by CloudPanel. It handles the SSL certificate (the padlock 🔒) and forwards the request to our app on port 3000. One server can host many sites; nginx sends each domain or subdomain to the right app.

  3. 3

    The Node.js app decides what to show

    Node.js runs our JavaScript code. A library called Express looks at the address (/, /admin, /how-it-works…) and runs the matching piece of code. These are called routes.

  4. 4

    It reads the database

    The app asks the SQLite database (one file, data/pulse.db) for the list of websites and their latest checks.

  5. 5

    It fills in a template and sends HTML back

    Pages are written as EJS templates: normal HTML with blanks where the data goes. The app fills the blanks and sends the finished page to your browser, which draws it using style.css. All of this takes a few milliseconds.

2 · The automation (runs by itself)

When the app starts, it also starts a timer called the scheduler. Every 5 minutes it:

  1. Gets every website from the database.
  2. Visits each one at the same time and measures how many milliseconds it takes to answer.
  3. Marks it Up if the answer is OK (a status code below 400), or Down if it is an error, times out after 10 seconds, or the domain doesn't exist.
  4. Checks how many days are left on its SSL certificate.
  5. Saves the result. If the status changed (up → down or down → up), it records an event. This is where an email or WhatsApp alert could go later.
  6. Deletes results older than 7 days so the database stays small.

That's the core idea behind most automations: a trigger (a timer, a form, an email) → some work (fetch, process, decide) → a result (save, notify, send).

3 · What keeps it running

A program called PM2 keeps the app alive. If the app crashes, PM2 restarts it. If the server reboots, PM2 starts it again. PM2 also stores the app's logs, the messages the app prints, like [checks] checked 4 sites.

4 · Where everything lives

All files are in /home/shanamota/htdocs/www.shanamota.online/ on the VPS.

FileWhat it does
src/server.jsThe web server. Defines every page (route), the login, and the admin actions.
src/scheduler.jsThe automation timer: checks all sites every few minutes.
src/checker.jsVisits one website, times it, and reads its SSL certificate.
src/db.jsCreates the database tables and has every read/write function.
src/config.jsReads settings from .env.
src/helpers.jsSmall helpers: "5 min ago", cleaning up typed-in URLs.
views/*.ejsThe page templates (HTML with blanks).
public/style.cssThe design: colours, spacing, fonts, dark mode.
.envSecret settings: admin password, check interval. Never share this file.
data/pulse.dbThe database file.
package.jsonThe project's ID card: its name and which libraries it uses.
ecosystem.config.cjsTells PM2 how to run the app.

5 · Try it yourself

  • Open /api/status. It's the same data as the home page, but as JSON, a format other programs can read. That is what people mean by an API.
  • Open a page that doesn't exist, like /nothing-here, to see a 404 error.
  • Log in to Admin, add a website, and watch the automation pick it up.