Hi all, I’ve been using Deno the past few days for development in an Elm project and would like to report on my experience. In a word: Its great!!!. But first:
Deno is a runtime for JavaScript and TypeScript that is based on the V8 JavaScript engine and the Rust programming language. It was created by Ryan Dahl, original creator of Node.js, and is focused on productivity.
Below is my experience in two parts.
Part 1: Building a server
I started off using Deno to build a little server that talks to an Elm app. The code is written in typescript, though one can also use javascript. Here is the repo, which I post with following notes, caveats, and lame excuses:
-
My first attempt using Deno, Typescript.
-
The code in
src
is working, while that insrc2
is a rewrite-in-progress based on a different data model. -
I had one issue that held me up for a day: you have to write your own OPTIONS handler. Thanks to all on Slack who helped me get through this.
-
The server uses the Oak middleware package.
Part 2: Script runner
I’ve always preferred writing little shell scripts to manage development. That said, the script runner part of npm
is really nice, despite the heavy baggage that comes with npm
. Yes, node_modules
, I am talking about you!
It turns out that there is another way: use velociraptor. The linked article, by velociraptor’s creator, Umberto Pepato (@umbo) explains how to install it and how to use it. In brief, you create a yaml
file which is the analogue of the scripts part of package.json
. Below is mine. It contains mixture of deno stuff and shell scripts. The first clause, start ...
could also have been written as a single line.
start: deno run src/server.ts --allow-net --allow-env ...
You run scripts by saying, for example, vr start
. Three cheers for Ryan Dahl and Umberto Pepato for creating these wonderful tools.
scripts.yaml
scripts:
start:
cmd: src/server.ts
allow:
- net
- env
- write
- read
test:
cmd: src2/file.ts
allow:
- read
- write
ssh: ssh root@161.35.125.40
upload: scp -r ./src root@161.35.125.40:/root/docserver
upone: scp $1 root@161.35.125.40:/root/docserver