How to start with Deno? Create HTTP server using Deno
Here we discussed the installation process of Deno and will create an HTTP server using Deno
How to Install
firstly we need to install Deno in our system.
for Mac or Linux, use the following command
curl -fsSL https://deno.land/x/install/install.sh | sh
for Windows
iwr https://deno.land/x/install/install.ps1 -useb | iex
After installation to check it successfully installed, type deno in the terminal and you will get following screen
now as announced deno support typescript, let’s check it
write a simple function to add two numbers in typescript
save it and execute using the command
deno run add.ts
yes! as we can see here deno supports Typescript.
Create HTTP Server
Since in deno we use ES module so we don’t need to require module as we did in node, and also don’t need to install npm packages. in Deno, we simply import as we did in react and here we import modules directly from web-server. E.g.
import { serve } from “https://deno.land/std@0.54.0/http/server.ts";
and when we run this code it will download whatever stored in this URL “https://deno.land/std@0.54.0/http/server.ts” and cache it locally. and whenever you run this code it will use data from its cache. this one is the replacement of npm packages.
Above you can see there is used await without async, this is a new feature of deno, here we can use top-level await.
Here we are almost done, now type the following command to run above code
deno run --allow-net denoServer.ts
and you will get following screen
if you want to know How to create HTTP server with Node, check here
Thanks…
Reference - https://deno.land
if have any doubt or query please reach out to me
Email-sachinkumar9663@gmail.com
Follow here for daily updates Instagram/jsdevlopers