~ev/denobook

ref: c87fd614fd60fa7566eb8ff3e4fc9508ff0f8071 denobook/hello.md -rw-r--r-- 1.6 KiB
c87fd614Ev Bogue correction 5 months ago

#Hello World in Deno

Node isn't going anywhere. –Ryan Dahl

Deno is a runtime for programming applications with JavaScript, it is similar and often compared with Node.js.

Node.js and Deno were both initially designed by the same guy, Ryan Dahl, but Deno is the direct response to the mistakes that Ryan thinks he made when designing Node. He presented a talk where he explained what went wrong with Node.js and why he thinks there is a reason for Deno to exist, it is here: 10 Things I Regret About Node.js - Ryan Dahl - JSConf EU [YouTube]

Node.js and Deno both allow you to write programs in JavaScript on servers, but in slightly different ways. If you've been hacking together Node.js programs for the past fifteen years, you'll need to unlearn a few habits to use Deno.

Deno imports modules directly via URLs, so you do not need to install a program that manages your modules for you.

For example, here is the Hello World script from Deno's website:

import { serve } from "https://deno.land/std/http/server.ts";
serve(req => new Response("Hello World\n"));

src [Deno.land]

To run the above program you need to use a text editor, save it as a file, such as serve.js and then run it using the following command in your terminal.

And if you have not done so already, you need to install Deno on your computer using the installation instructions at Deno.land

deno run serve.js

And you will be able to visit the application you've programmed at http://localhost:8000/ where you should see the words "Hello World".