loading...
Cover image for Great fun with Deno - My First Deno Framework

Great fun with Deno - My First Deno Framework

oknoorap profile image Ribhararnus Pracutian ・4 min read

We're already heard that Deno release its first major version (v1.0) about several weeks ago, and it was shakes JS world, little bit.

If you read this post, and you're new in JS (or maybe Node), I suggests you to learn TypeScript first, before you try develop something with Deno. But, it doesn't matter after all, Deno is both Javascript and TypeScript runtime, so don't worry.

My reaction when I heard about Deno incoming release, was the same like other JS developer. I called it adage in JS world, "Here we go again, there will be a new Framework or Library every day, even, it's every seconds now."

I've already tried and playing with Deno in 2018 - early-to-mid 2019, but it's not stable yet. After they release v1.0, I tried it again, and praising-word came from my mouth, "Hey, it's really fun, some feature and bug have been fixed."

Although it's just a beginning, and Deno is not ready yet for production-ready application. I believe Deno will be huge someday just like Node. Ryan Dahl, the creator of both, Node and Deno is visionary after all. I trust him and the OSS community behind Deno.

If you're Go programmer, you may notice that Deno has similar dependencies mechanism. You don't need to install dependencies, instead you import it directly with http/https protocol, and later it will be cached in specified directory.

What I like about Deno

  • You don't need Package Manager (NPM / Yarn).
  • You don't need to install TypeScript.
  • Smaller executable size than Node.
  • You can import files anywhere (via HTTP protocol or file protocol easily)

🦖 Jurassic

While I'm learn how Deno works, async-await, dynamic import and Deno file system, I accidentally created this framework. I called it Jurassic.

Yup, that's my framework name. A geological period where dinosaurs live. I describe this framework as "A Straightforward REST API Framework".

Is it another JS Framework? yes it is, and hmmm no.

Okay, I admit it, it was another saturated JS framework, but, I really working on this framework just for fun, don't judge me.

But, it also different from any other frameworks out there (for now).

Jurassic is a simple REST Framework server, you don't need a setup (still, you can create custom config). Jurassic have magic part which other framework doesn't have.

The Magic Part

I'm NextJS developer and I really inspired with NextJS Dynamic Routes, so I adopts it in Jurassic.

In my view, builds a REST API server should be easy, instant and should have zero config. We don't need anything, it's should be straightforward. What we need is simple, we need how to manages route, handling a request and give a response to client.

That's why we don't need to setup a config or boot file. Just start a REST API server and done.

In Jurassic Framework you should have a routes directory. Where is router definition? use file name as router, and thats it.

<your_directory>
|__ routes
|____ hello.ts

Done. Now run this in <your_directory>:

deno run --allow-read --allow-net --allow-env https://deno.land/x/jurassic/server.ts

Access from your favourite Browser:

http://localhost:8888/hello

It's simple and Straightforward.

Dynamic Router Params

As I said before, I really like NextJS approach with their Dynamic Routes.

When you have file name with in-bracket variable like this:

[param].ts

## or
posts/[postId].ts

## or
post-[id]-by-[author].ts

you can call it dynamic params, and you can access those params in route handler like this:

// console.log(req.params.[yourParamName])

// e.g
// filename: [postId].ts
console.log(req.params.postId)

Fun, right?

There is so much room to improve within this framework, such as middleware, hooks, plugins, and other framework features that I don't have it yet. Remember, I created Jurassic Framework just for fun 😉, when I learn Deno weeks ago, don't expects much from me.

If you're interested with Jurassic Framework, you can see more example and play with it in my repo below. Submit a PR to my repo, that's how OSS community works.

🔗 Link and Repo

🦕 Deno Std
https://deno.land/x/jurassic

👉 Github Repo
https://github.com/oknoorap/jurassic

🎉 Example Codes
https://github.com/oknoorap/jurassic/tree/develop/examples

👨🏻‍💻 Next Framework

With Deno I can do almost anything, I can do what I can't do with Node. I codes faster with Deno. I don't need any tooling, any dependencies, and of course I don't need Microsoft NPM registry account. I can serve / import my script or codes anywhere.

So, next time, I want to create a Game Engine Framework based on Phaser + TypeScript which will have magic element like Jurassic.

I think I'm not or one of Rockstar Developer, but if you're interested and wanna join with me building something fun, you can drop me a message via twitter @oknoorap.

Thank you. 🥳

Posted on Jun 2 by:

oknoorap profile

Ribhararnus Pracutian

@oknoorap

Web Developer and Tech Enthusiast

Discussion

markdown guide
 

Despite your knowledge about NextJS, you have some issues with the English language. If you study a little bit more about prepositions 'with' and 'by' and the use of third-person, you will write better. Keep studying. Congratulations!

 

Thanks, english is not my primary language.

 

Quick silly question from someone with 0 Deno knowledge: how does one connect this (or any generic Deno app) to any kind of UI/view library?

 

I've only just read myself into the docs. Deno is a scripting environment, so you can feed it scripts and let it execute those. It's not meant to be a backend for serve a UI. There are other tools for that purpose.

 

You can serve a UI with a templating engine and web server, like: github.com/NMathar/deno-express

 

Did you say Deno is not for writing Backends? It is for fast & secure backends but maybe I didn't understand your answer.

That's why I corrected it.

Deno can serve as a backend, of course. But as a scripting runtime it is not meant to serve a UI itself (directly).

Of course, you can run a backend on Deno and have a separate UI consume its API.

Is Java also a scripting language? I mean both languages need a runtime to run on server, Java & JS

I think the difference is Java can be compiled, scripting language can't be compiled, need JIT and runtime.

No, Java is compiled into bytecode that is then run on the Java Virtual Machine (JVM), which itself is just an abstraction of the underlying real architecture.

yes you're correct 👍, scripting languange can't be compiled into bytecode.

 

Good question, My framework is with specific purpose, it's to build a quick REST API server, so I don't have any plan to add any views or renderer functionality, but still you can set content type as text/html in router response.

 

What build tools do you use for the frontend? Do you consider non-Node.js based, like esbuild, or do you use traditional ones?

 

Deno support TypeScript and I believe Deno already has bundler tooling, your source code will be compiled as ES, you can read about Deno bundler here deno.land/manual/tools/bundler

 

I don't think TypeScript (or Deno) can compile codes into minify version 😁, but we can do that later using terser or TypeScript plugin or similar tool. That's what I know, maybe someone knows better than me ✌️

I agree with you, with Deno we can run our code faster enough on the server, even we're not bundling it.

Yes, I was referring to frontend code, with problems of

  • Bundle size and data usage on the clients
  • caniuse.com/ i.e. browser support

I almost never minify backend code. Just mere tsc. Not even Babel. Never that big compared to node_modules anyway.

node_modules is heavy.

Thats why Deno is the big rescue here 😁, we don't need node_modules anymore.

 

I'm curious about Deno as well as most others in this community. However, some of your statements got me thinking:

  • You don't need dependencies in Deno ? You don't need dependencies in NodeJs either .
  • What is there that you can't do in NodeJs, but with Deno ?

I am relatively new to coding (< 5 years) and reading things like that are easily misinterpreted. Try giving examples to underline those statements.

Other than that, good read ! Jurassic sounds awesome !

 

of course we need dependencies but no need to install it, you can import directly from URL 😀

 
 

can someone post some great open source projects build with deno ?

 

It's still early, let's wait next three or six month later. But actually, every npm pkg can be imported via pika or jspm.