Reputation: 3085
I am trying to use Deno, and I've came to a script called Attain, which looks so much similar to Express.
Express snippet:
const express = require('express')
const app = express()
app.get('/', function (req, res) {
res.send('Hello World')
})
app.listen(3000)
Attain snippet:
import { App, Router } from "https://deno.land/x/attain/mod.ts";
const app = new App();
app.get('/', (req, res) => {
res.send("Hey there!");
});
app.listen({port: 8080});
It looks promising to start using it as a middleware framework, but I am looking for an experienced opinion about whether Attain contains the same internal functionalities as Express, and whether there are differences between them?
Upvotes: 1
Views: 306
Reputation: 495
The closes i get when finding a web framework for Deno is OAK, its the most popular one out there that is available, other abc and pogo, but so far OAK is the best and goto with routers and middlewares. You can find a detail article about Building a simple REST API with Deno and OAK on medium for better understanding.
Upvotes: 0
Reputation: 21
It's concepts and middlewares, and all the things are coming from the express.js concept. but the procedures are a little different. for one thing, Attain doesn't have next() method due to the fact that it is a step by step async based procedure. It will not stop until it faces the send() or end() method.
: GET method /
import { App, Router } from "https://deno.land/x/attain/mod.ts";
const app = new App();
app.use((req, res) => {
console.log("First step");
res.whenReady(() => {
console.log("Fourth step");
});
});
app.get("/hello", (req, res) => {
console.log("Second step but will skip it because of url unmatched.");
});
app.get('/', (req, res) => {
console.log("Third step");
res.status(200).send("The fifth step has responded.");
});
app.use((req, res) => {
console.log("It does not reach here.");
});
app.listen({port: 8080});
I can say oak is highly expended and ready to use because it has been developed for a long time. But the Attain library has been released a few days ago.
Upvotes: 2
Reputation: 1683
Currently, the web framework that is the closest to Express with Deno is oak
https://github.com/oakserver/oak
If you are familiar with JavaScript middleware frameworks like Express and Koa it will be easy to understand and use
Upvotes: 1