Server - Contents

MojoJS-PartB

new: 01-Dec-2025

Minimal Blog App with Pg Database

Prerequisites:

That the Postgres database application is installed and ready to receive queries.

Introduction
The given example is actually found Mojo.js-Blog and demonstrates the efficient tools mojo.js provides as well as an excellent reference for the development of API and other web-database applications. Further references to consider are; @mojojs/pg and @mojojs/sql.

sammy@imega:$ tar -xzvf mjpg251130.tar.gz
sammy@imega:$ chmod -R 744 pg/ // set the permissions
sammy@imega:$ cd pg
sammy@imega /pg:$ bun install
sammy@imega /pg:$ bun run dev Open the browser at http://localhost:3000 Press Ctl-C to quit.
Notes:
- Should the pg user: postgres have a password, it needs to be added to the connection string found in config.yml
- In the controllers directory, the routes can be set in 'post.js' with optional parameters which in turn call the sql queries from models/blog.sql
- The index.js calls these routes together with addition parameters such as setting the 'title'.
- A number of the helper tags (see Mojo.js-Cheatsheet) are used in the application.
- All static files are rendered from the 'public' directory (or sub-directories therein).
- The helper tags are used to render images, eg %= await tags.image('img/tree.png') from the public/img directory.
- The full example can be downloaded here: mjpg251130.tar.gz (~3kB) - place and unzip this file in the home directory.
MojoJS MojoJS-Blog
MojoJS-Deploy MojoJS-Extras