Deno Experience

Royson D'Silva
3 min readApr 10, 2022

--

Recently I applied at Toptal to boost my freelance career. Toptal has a great selection process with interviews and take home assignment. For confidentiality reasons I can’t disclose the interview and assignment question but one thing I can share is the assignment was to develop a web-app since I’d applied for work as a full-stack developer. The thing with this assignment is they give a detailed statement of what needs to be done and complete implementation freedom.

The Deno Logo

So I went with ReactJS for frontend and thought of experimenting with Deno for backend. For the uninitiated, Deno is a runtime for JS and TS that was created by Ryan Dahl who also created Node.js. You can find the reason for Deno in the video below 👇

Moving on… Using Deno was such a breeze. It supports TypeScript out of the box. One doesn’t need to download npm install packages. Just provide a url of the code you need and it starts executing. Under the hood it does download the code locally and caches it but as a developer you don’t need to worry about managing the packages.

To get started install Deno in your machine. Instructions here: https://deno.land/manual@v1.20.5/getting_started/installation. Create a TS file call it app.ts. Paste the below code to app.ts 👇

console.log("Hello World");

Save the file and run it with deno run app.ts. That’s all needed to get started with Hello World example.

Deno comes with a built-in formatter and testing framework, run deno fmt and deno test respectively, and done.

Deno also has instructions to setup your environment. This let’s you get intelli-sense in your IDE and terminal. For those using VS Code extension and have Volar extension installed you need to disable Volar when using the deno extension. I spent half an hour trying to figure why Deno extension was not working. Turns out the 2 extension conflict since Volar doesn’t have Deno globals. Rest of the stuff just worked. Every time that I had to do a node.js setup I don’t think I had such smooth experience with setup ever. Kudos to the deno team 👏.

As for building the backend, I could build everything from scratch but that would take some time. The good part of node.js was the huge community with it’s many libraries and frameworks that makes it easier to build a backend. Hence I started for looking for express.js equivalent for deno. The first result was Oak. This framework is just as easy as express.js, comes with router and in less than 10 lines the server was up (including routes).

I prefer separate ports for my client and server applications and this means I need to enable CORS for my server endpoints. And guess what, deno has a package for that as well — cors. The deno community is growing and has tools for most of the basic use-cases like jwt and bcrypt.

I also needed a database so I went with MongoDB cause I’m comfortable working with it. Deno does have a mongo package and it is very easy to begin with but it’s not as mature as mongoose. Also, while connecting to the local mongo instance the docs mentions the following command:

await client.connect("mongodb://localhost:27017");

This doesn’t work and one needs to replace localhost with the IP — 127.0.0.1

await client.connect("mongodb://127.0.0.1:27017");

This one issue with connecting with mongo was the only hiccup I faced while working with deno. I went with using the mongo package in deno but the folks at MongoDB suggest using the Data API. You can read all about it in — Getting Started with Deno & MongoDB. Please share your experience if you’ve tried this out.

Overall it’s just as smooth as node.js with added bonus of security. The community is small but growing. At the time of writing this post deno has 4k+ third-party modules.

If this post motivated you to try deno, please go ahead and let me know your experience in the comments.

--

--

Royson D'Silva

Working as a freelancer + building things in spare time (both mostly in software). List of my personal work — droyson.xyz