loading...
Cover image for Deploy deno in 4 steps

Deploy deno in 4 steps

gokulkrishh profile image Gokulakrishnan Kalaikovan Updated on ・2 min read

What is deno?

Deno is secure run time for javascript & typescript. Deno aims to provides secure scripting environment. It is built on top of V8 engine, Rust and TypeScript. Also deno supports typescript out of the box.

Goal

  • Create a simple todo rest api.
  • Use oak middleware for routing etc,
  • Expose routes for GET, POST, DELETE and PUT methods.

Demo

API list

  • GET - /
  • GET - /todos
  • POST - /todos (form data)
  • PUT - /todos/:id (form data)
  • DELETE - /todos/:id

Project structure

.
├── Dockerfile
├── LICENSE
├── README.md
├── config.js
├── controllers
│   └── todos
│       ├── delete.js
│       ├── get.js
│       ├── post.js
│       └── put.js
├── data
│   └── todos.json
├── fly.toml
├── index.js
└── router.js

Source code

Install & Run

Step 1: Install

curl -fsSL https://deno.land/x/install/install.sh | sh

Step 2: Run

deno run --allow-net --allow-read --allow-write ./index.js

Note:

--allow-net is to allow network access
--allow-read is to allow read access to file system
--allow-write is to write to file system.

Step 3: Open https://localhost:8080

Step 4 (optional): denon for deno like nodemon for node

deno install --unstable --allow-read --allow-run -f https://deno.land/x/denon/denon.ts

denon ./index.js

Note:

Denon uses .denonrc.json file in root for configuration

Step 5 (optional): To run using docker


docker build -t app . && docker run -it --init -p 8080:8080 app

Deployment

Deployed using https://fly.io/ with docker.

Deploy in 4 steps

  1. Install Flyctl - you'll need it.

  2. Sign up/Log in to Fly - run flyctl auth signup to create an account or flyctl auth login to log in.

  3. Run flyctl apps create - let Fly generate you a name (recommended) or enter one of your own. Generates fly.toml file with config.

  4. Run flyctl deploy - To deploy

Run flyctl info - Fly will deployment details.

Hope this post was helpful. If you have any questions or query comment below.

Follow me on twitter for more web related things.

Posted on Mar 17 by:

gokulkrishh profile

Gokulakrishnan Kalaikovan

@gokulkrishh

Web Dev @Thoughtworks, GDE for Web, Speaker, Curator at @thisweekinweb, Author of http://how-it-works.dev & github: http://github.com/gokulkrishh

Discussion

markdown guide