Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mojolicious/mojo.js
:unicorn: The Mojolicious real-time web framework for Node.js
https://github.com/mojolicious/mojo.js
backend javascript mojojs mvc nodejs typescript web-framework websockets
Last synced: about 17 hours ago
JSON representation
:unicorn: The Mojolicious real-time web framework for Node.js
- Host: GitHub
- URL: https://github.com/mojolicious/mojo.js
- Owner: mojolicious
- License: mit
- Created: 2021-04-23T22:47:52.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-15T08:56:50.000Z (24 days ago)
- Last Synced: 2024-10-29T04:34:32.582Z (11 days ago)
- Topics: backend, javascript, mojojs, mvc, nodejs, typescript, web-framework, websockets
- Language: JavaScript
- Homepage: https://mojojs.org
- Size: 4.4 MB
- Stars: 486
- Watchers: 26
- Forks: 33
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: docs/Contributing.md
- License: LICENSE
- Authors: AUTHORS
Awesome Lists containing this project
- awesome - mojolicious/mojo.js - :unicorn: The Mojolicious real-time web framework for Node.js (JavaScript)
- awesome - mojolicious/mojo.js - :unicorn: The Mojolicious real-time web framework for Node.js (JavaScript)
README
[![](https://github.com/mojolicious/mojo.js/workflows/test/badge.svg)](https://github.com/mojolicious/mojo.js/actions)
[![Coverage Status](https://coveralls.io/repos/github/mojolicious/mojo.js/badge.svg?branch=main)](https://coveralls.io/github/mojolicious/mojo.js?branch=main)
[![npm](https://img.shields.io/npm/v/@mojojs/core.svg)](https://www.npmjs.com/package/@mojojs/core)The [Mojolicious](https://mojolicious.org) real-time web framework for [Node.js](https://nodejs.org/). Written in
TypeScript. Meticulously designed for hypermedia-driven backend web services using all the latest JavaScript features.If you want to stay up to date on the
[latest developments](https://github.com/mojolicious/mojo.js/blob/main/CHANGELOG.md) join us on
[IRC](https://web.libera.chat/#mojo).## Features
* 3x faster than Express.js and 15x faster than Mojolicious.
* A **real-time web framework**, allowing you to easily grow single file prototypes into well-structured MVC web
applications.
* Powerful out of the box with RESTful routes, WebSockets, plugins, commands, logging, templates, content negotiation,
session management, form and JSON validation, testing framework, static file server, cluster mode, CGI detection,
first class Unicode support and much more for you to discover.
* A powerful **web development toolkit**, that you can use for all kinds of applications, independently of the web
framework.
* High performance HTTP and WebSocket client/server implementation with support for HTTPS/WSS, cookies, redirects,
urlencoded/multi-part forms, file uploads, JSON/YAML, HTML/XML, mocking, API testing, HTTP/SOCKS proxies, UNIX
domain sockets and gzip compression.
* HTML/XML parser with CSS selector support.
* No frontend framework, mojo.js is for the **backend**.
* Written in [TypeScript](https://www.typescriptlang.org), with very clean `class` and `async`/`await` based APIs.
* Very few dependencies, to avoid supply chain attacks and allow for "Perl-grade" long term support and
**backwards compatibility**.
* Fresh code based upon decades of experience developing [Mojolicious](https://mojolicious.org) and
[Catalyst](http://catalyst.perl.org), free and open source.## Installation
All you need is Node.js 18.0.0 (or newer).
```
$ npm install @mojojs/core
```Maybe take a look at our high quality spin-off projects [@mojojs/dom](https://www.npmjs.com/package/@mojojs/dom),
[@mojojs/path](https://www.npmjs.com/package/@mojojs/path), [@mojojs/pg](https://www.npmjs.com/package/@mojojs/pg) and
[@mojojs/template](https://www.npmjs.com/package/@mojojs/template).## Getting Started
These four lines are a whole web application.
```js
import mojo from '@mojojs/core';const app = mojo();
app.get('/', ctx => ctx.render({text: 'I ♥ Mojo!'}));
app.start();
```Use the built-in command system to start your web server.
```
$ node index.mjs server
[77264] Web application available at http://127.0.0.1:3000/
```Test it with any HTTP client you prefer.
```
$ curl http://127.0.0.1:3000/
I ♥ Mojo!
```## Duct Tape for the Web
Use all the latest Node.js and HTML features in convenient single file prototypes like this one, and grow them easily
into well-structured **Model-View-Controller** web applications.```js
import mojo from '@mojojs/core';const app = mojo();
app.get('/', async ctx => {
await ctx.render({inline: inlineTemplate});
});app.websocket('/title', ctx => {
ctx.plain(async ws => {
for await (const url of ws) {
const res = await ctx.ua.get(url);
const html = await res.html();
const title = html.at('title').text();
await ws.send(title);
}
});
});app.start();
const inlineTemplate = `
const ws = new WebSocket('<%= ctx.urlFor('title') %>');
ws.onmessage = event => { document.body.innerHTML += event.data };
ws.onopen = event => { ws.send('https://mojolicious.org') };`;
```## Want to know more?
Take a look at our excellent [documentation](https://mojojs.org/docs/)!