In this tutorial i want to show you how to data in Deno with typescript
Deno is a secure runtime for JavaScript and TypeScript. Deno is written in Rust. It builds on top of the Tokio platform and, like Node.js, executes JavaScript using the V8 engine.
To download Deno, follow the instructions on the Homepage. At this time of the post the last version of Deno is 1.0
By default, Deno is compatible with more Web APIs. you can show the list at the end of this post
I will use typescript in this tutorial but you can use Javascript, it will work.
Create a file called
main.ts
in the root directory of our code editorin our
main.ts
file, we are going to create a async function that take an argument and call thefetch
Web API to fetch external data.
const getUser = async (url: string): Promise<void> => {
const data = await (await fetch(url)).json();
console.log(data);
};
getUser("https://jsonplaceholder.typicode.com/users");
By default Deno is secure and it doesn't allow us to have acces of network, file system, etc...
To execute our file we are going to do this
deno run --allow-net main.ts
The --allow-net
flag allow us to have an access for the network.
Web APIs compatible with Deno
addEventListener
atob
btoa
clearInterval
clearTimeout
dispatchEvent
fetch
queueMicrotask
removeEventListener
setInterval
setTimeout
AbortSignal
Blob
File
FormData
Headers
ReadableStream
Request
Response
URL
URLSearchParams
console
isConsoleInstance
location
onload
onunload
self
window
AbortController
CustomEvent
DOMException
ErrorEvent
Event
EventTarget
MessageEvent
TextDecoder
TextEncoder
Worker
ImportMeta
Location
Top comments (0)