Create a free and quick backend for Hype using Deno(.com)

Deno is a new JavaScript runtime that is based on the V8 JavaScript engine. Deno is for developers who want to build applications that are more secure and efficient. Deno uses TypeScript, which is a superset of JavaScript that provides static type checking. Deno also has a more modern module system, which is more efficient than the traditional CommonJS module system.

The benefits of Deno include security, efficiency, and TypeScript support. Deno is more secure because it runs in a sandbox, which means that it can't access the file system or network by default. Deno is also more efficient because it doesn't need a build step, and it can lazy-load modules.

Pricing for Deno is subscription-based, and starts at $10/month, but they have a very generous free tier you will probably never surpass.

If you want to start using Deno, sign up for a playground account on Deno Deploy. This playground account gives you access to a web-based IDE where you can write and run Deno code.

To create your first app in the playground, click the "New App" button. This will open a new window where you can enter the name of your app and choose a template. For this example, we'll use the "Hello World" template.

Once you've chosen a template, Deno will generate some boilerplate code for you. This code includes a basic web server that will respond to requests at the root URL "/".

To run your app, click the "Run" button. This will start the web server and open your app in a new browser tab. You should see the "Hello World" message displayed in the browser.

Now that you've seen how to create and run a simple Deno app, you're ready to start building more complex applications. Deno has a wide range of features that you can use to build powerful and scalable apps.

When you visit the playground at Deno Deploy, you may notice that the default return value is "Hello world!"

While this is a perfectly valid return value, you may be interested in returning more complex data structure, such as a JSON file.

Luckily, returning a JSON file from the playground is a relatively simple process.

First, you will need to create a new project in your playground. This will contain the default example TypeScript code that will be executed when you run the playground.

This code will start a web server on port 8000 and return the text "Hello world!" when you visit the playground.

It is pretty easy to modify the return value to return a JSON string. Check the following code to serve a JavaScript object as a JSON string.


import { serve } from "https://deno.land/std@0.145.0/http/server.ts";

serve((req: Request) => new Response(
    JSON.stringify({
        message: "Hello world!",
        a: 2*2,
    })
));

You can also return other data in your JSON file, such as settings or application data.

If you have any questions about returning a JSON file from the playground, feel free to ask in the comments section below.

3 Likes