GithubHelp home page GithubHelp logo

linecode / mojo.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mojolicious/mojo.js

0.0 1.0 0.0 4.05 MB

:unicorn: The Mojolicious real-time web framework for Node.js

Home Page: https://mojojs.org

License: MIT License

JavaScript 57.75% Perl 0.13% TypeScript 42.07% Raku 0.05%

mojo.js's Introduction

Coverage Status npm

The Mojolicious real-time web framework for Node.js. 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 join us on Matrix or IRC.

Features

  • 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.
  • Very clean, class and async/await based API, written in TypeScript, with very few requirements to avoid NPM dependency hell and allow for "Perl-grade" long term support.

  • Fresh code based upon decades of experience developing Mojolicious and Catalyst, free and open source.

Installation

All you need is Node.js 16.0.0 (or newer).

$ npm install @mojojs/core

Maybe take a look at our high quality spin-off projects @mojojs/dom, @mojojs/template and @mojojs/path.

Getting Started

These four lines are a whole web application.

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.

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();
      ws.send(title);
    }
  });
});

app.start();

const inlineTemplate = `
<script>
  const ws = new WebSocket('<%= ctx.urlFor('title') %>');
  ws.onmessage = event => { document.body.innerHTML += event.data };
  ws.onopen    = event => { ws.send('https://mojolicious.org') };
</script>
`;

Want to know more?

Take a look at our excellent documentation!

mojo.js's People

Contributors

kraih avatar marcusramberg avatar dependabot[bot] avatar jberger avatar grinnz avatar doojonio avatar dmanto avatar kiwiroy avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.