Opine

Jul 5, 2024 | Programming

A minimalist web framework for Deno ported from ExpressJS.

Deno reading an opinionated book

Current version Current test status Deno docs PRs are welcome Opine issues Opine stars Opine forks Opine license Opine is not maintained Published on nest.land Opine latest x version Minimum supported Deno version Opine dependency count Opine dependency outdatedness Opine cached size

Now in maintenance mode: Deno has introduced Node and NPM compatibility, considering using Express itself in Deno (source)!

Table of Contents

Getting Started

ts
import opine from "https://deno.land/x/opine@2.3.4/mod.ts";

const app = opine();
app.get("/", function (req, res) {
    res.send("Hello World");
});
app.listen(3000, () => console.log("server has started on http://localhost:3000"));

In the above code, we create a simple web server using Opine. Think of it like crafting a recipe for a delightful meal. The ingredients are your code:

  • Importing Opine: Similar to getting your ingredients ready. Here, we bring in the Opine framework.
  • Creating the app: This is akin to cooking; you’re preparing a delicious dish called a “web server”.
  • Setting the route: You’re instructing where to serve your meal (the “Hello World” message) when someone visits the dedicated location (“/”).
  • Starting the server: This is when you put your dish in the oven! The server is ready and waiting for guests at “http://localhost:3000”.

Installation

This is a Deno module available to import directly from this repo and via the Deno Registry.

Before importing, download and install Deno.

You can then import Opine straight into your project:

ts
import opine from "https://deno.land/x/opine@2.3.4/mod.ts";

Opine is also available on nest.land, a package registry for Deno on the Blockchain:

ts
import opine from "https://x.nest.land/opine@2.3.4/mod.ts";

Features

  • Robust routing
  • Large selection of HTTP helpers including support for downloading, sending files, etags, Content-Disposition, cookies, JSONP etc.
  • Support for static serving of assets
  • View system supporting template engines
  • Content negotiation

Documentation

Quick Start

The quickest way to get started with Opine is to utilize the Opine CLI to generate an application as shown below:

bash
deno install -f -q --allow-read --allow-write --allow-net --unstable https://deno.land/x/opine/cli@2.0.0/opine-cli.ts

And follow any suggestions to update your PATH environment variable:

bash
opine-cli --view=ejs hello-deno  
cd hello-deno

Start your Opine app at “http://localhost:3000”:

bash
deno run --allow-net --allow-read --allow-env mod.ts

Philosophy

The Express philosophy is to provide small, robust tooling for HTTP servers, making it a great solution for single page applications, web sites, hybrids, or public HTTP APIs. Opine aims to achieve these same great goals, focusing on providing equivalent robust tooling and features for Deno users.

Now Deno’s Node compatibility layer is maturing sufficiently to support Express out of the box, Opine is operating in maintenance mode.

Examples

To run the examples, you have two choices:

  • Run the example using Deno directly from GitHub, for example:
    • bash
      deno run --allow-net --allow-read https://raw.githubusercontent.com/cmorten/opine/main/examples/hello-world/index.ts
      
  • Clone the Opine repo locally:
    • bash
      git clone git:github.com/cmorten/opine.git --depth 1  
      cd opine
      
    • Then run the example you want:
      • bash
        deno run --allow-net --allow-read .examples/hello-world/index.ts
        

All the examples contain example commands in their READMEs to help get you started for either of the above methods.

Contributing

See the Contributing guide for more information.

License

There are several third-party modules that have been ported into this module. Each third-party module has maintained its license and copyrights. The only exception is for Express, from which this entire module has been ported, whose license and copyrights are available at EXPRESS_LICENSE in the root of this repository, and cover all files within the source directory which have not been explicitly licensed otherwise. All modules adapted into this module are licensed under the MIT License. Opine is licensed under the MIT License.

Icon designed and created by Hannah Morten.

Troubleshooting

If you run into any issues while using Opine, here are some troubleshooting tips:

  • Check to ensure that Deno is properly installed and updated to the required version.
  • Ensure the module URL is correct and accessible.
  • Look for error messages in your terminal for clues on what might be wrong.
  • If things still don’t work, visit the Opine issues page for assistance from the community.
  • For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox