Mojo.js was founded by Sebastian Riedel and other collaborators. The project is still under his direction. This is the third successful project from his earlier brilliant ones of Catalyst and Mojolicious which are based on Perl. With excellent documentation replete with examples, mojo.js stands out as a solid foundation for any web project.
The following example, outlined below, demonstrates some of the basic code and helpers used to setup a simple website, having w3.css for styling. Bun.js was found more useful over npm.js.
Part A: Create a basic website
From the documentation Mojo.js-Growing one can choose the appropriate structure, even that for TypeScript. For this simple example, we will use that for a basic js structure.
sammy@imega:$ tar -xzvf fullmjapp251130.tar.gz
sammy@imega:$ chmod -R 744 full/ // set the permissions
sammy@imega:$ cd full
sammy@imega /full:$ bun install
sammy@imega /full:$ bun run dev Open the browser at http://localhost:3000 Press Ctl-C to quit.
Notes:
- In the controllers directory, the routes can be set in 'example.js' with optional parameters.
- The index.js calls these routes together with addition parameters such as setting the 'title'.
- Different layouts can be created as well as partial templates. Here the helper tag (see Mojo.js-Cheatsheet) eg. %= await tags.asset('w3.css') is used to link with this file placed in the public/assets directory.
- 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: fullmjapp251130.tar.gz (~126kB) - place and unzip this file in the home directory.