Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • NodeJS Tutorial
  • NodeJS Exercises
  • NodeJS Assert
  • NodeJS Buffer
  • NodeJS Console
  • NodeJS Crypto
  • NodeJS DNS
  • NodeJS File System
  • NodeJS Globals
  • NodeJS HTTP
  • NodeJS HTTP2
  • NodeJS OS
  • NodeJS Path
  • NodeJS Process
  • NodeJS Query String
  • NodeJS Stream
  • NodeJS String Decoder
  • NodeJS Timers
  • NodeJS URL
  • NodeJS Interview Questions
  • NodeJS Questions
  • Web Technology
Open In App
Next Article:
NodeJS Introduction
Next article icon

Deno.js | Introduction

Last Updated : 18 Dec, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

Introduction: DenoJS is a Secure runtime for JavaScript and TypeScript based on the V8 JavaScript Engine (developed by The Chromium Project, Google), Rust Programming Language and Tokio which is an asynchronous runtime for Rust. NodeJS is also a JavaScript runtime which uses the V8 engine. DenoJS 1.0.0 was released on May 13th, 2020 and is created by Ryan Dahl, who is also the creator for NodeJS.

DenoJS aims to be a productive and secure scripting environment to provide an easy experience for the modern age developers. The creators of NodeJS had expressed several concerns over the functioning of NodeJS. They had expressed concerns over the security of Node, how Node handled packages and other legacy APIs within Node which will never change, among other things. Node was released in 2009 and since then JavaScript has changed a lot. They wanted to make a better version of NodeJS with modern JavaScript tools and APIs. They also wanted something compatible with the Browser and Server Environments and hence came the realization of DenoJS.

Advantages and Features of DenoJS: 

  • Secure by Default: One of the biggest advantages of DenoJS is that it is Secure by Default. It runs in a Sandbox environment and unless specifically permitted, Deno isn’t allowed to access files, the environment, or the network which is not the case in NodeJS. To access the environment or the network we explicitly need to add Security flags and Permissions when executing a Deno application. If the respective flags are not added, It will give a PermissionsDenied error when running the application. The list of Security flags are provided below
    • –allow-write: Allow Write Access
    • –allow-read: Allow Read Access
    • –allow-net: Allow Network Access
    • –allow-env: Allow Environment Access
    • –allow-plugin: Allow loading External Plugins
    • –allow-hrtime: Allow High Resolution Time Measurement
    • –allow-run: Allow Subprocesses to run
    • -A: Allow all Permissions
  • Typescript: DenoJS supports Typescript out of the Box. We can use TypeScript or JavaScript while developing Deno applications since the TypeScript compiler is also included within Deno. Hence we can simply create a new .ts file and it will be successfully compiled and executed with Deno.
  • Single Executable File: DenoJS ships as a single executable with no dependencies. Deno attempts to provide a standalone tool for quickly scripting complex functionality. Like a web browser, it knows how to fetch and import external code. In Deno, a single file can define complex behaviour without any other tooling. Given a URL to a Deno program, it is runnable with nothing more than the 15 MB of memory. Deno explicitly takes on the role of both a runtime and package manager.
  • De-centralized Packages: One of the major drawbacks of NodeJS is how the dependencies are handled with NPM packages. For example, If we want to use Express with NodeJS, we would simply install using npm and the dependency would go to node_modules folder. The problem is that when Express is installed, it simply isn’t the Express package. It also includes the dependencies of Express. Hence we end up with lots of folders within node_modules, making the process of handling external packages extremely difficult as well as increasing the size of the application. DenoJS offers De-centralized Packages i.e. Deno does not use npm. There are no NPM packages for Deno and there is no package.json file and no node_modules dependencies folder. It uses a standard browser-compatible protocol for loading modules via URLs. It imports modules which are referenced via URLs or file paths from within the application. If we want to import and use an external module, we can simply Import it from the URL:
https://deno.land/x/[Package_Name]
  • Browser Compatibility: DenoJS was designed to be Browser Compatible. The set of Deno scripts which are written completely in JavaScript and do not use the global Deno namespace can also be executed using Deno in a modern web browser without any code change. Deno also follows the standardized browser JavaScript APIs. Since Deno is browser compatible, we have access and can use JavaScript APIs like fetch. We also have access to the global JavaScript window object.
  • ES Modules: Unlike NodeJS, Deno incorporates modern JavaScript syntax. Deno uses ES Modules (the import Syntax) and does not support the common JavaScript require Syntax used in NodeJS. All External ES modules are imported via URLs just like in GoLang, for example:
import { serve } from "https://deno.land/x/http/server.ts"

This Import is used to create a simple HTTP Server in Deno. Another Key feature of Deno is that after this module is imported, it is cached to the Hard drive on load. Remote code which is fetched will be cached to the Hard drive when it is first executed, and it will never be updated until the code is run with the –reload flag. According to official DenoJS documentation, modules and files loaded from remote URLs are intended to be immutable and cacheable.

  • Standard Modules: Deno has an extensive set of Standard Library Modules that are audited by the Deno team and are guaranteed to work with Deno. These standard modules are hosted here and are distributed via URLs like all other ES modules that are compatible with Deno. Some of these standard libraries are fs, datetime, http, etc much like the NodeJS modules. Deno can also import modules from any location on the web, like GitHub, a personal webserver, or a CDN (Content Delivery Network). There are more number of standard modules as well as external modules being added to Deno everyday.
  • Top Level Await: Another Core and important feature of Deno is top-level/First Class Await Syntax. In Deno, we can use the Await Syntax in the global Scope without having to wrap it in the Async Function. Also all async actions in Deno return a Promise which can remove/avoid the Callback Hell that Node can lead to due to nested callbacks.
  • Utilities: Deno provides built-In Testing and has built-in utilities like a dependency inspector (deno info) and a code formatter (deno fmt). Deno also allows direct execution of WebAssembly WASM Binaries. NodeJS is known for its HTTP and Data Streaming capabilities, however Deno is able to serve HTTP more efficiently than Node.

Installation of DenoJS: For the different ways on Installing DenoJS, Refer to this link. We will be Installing Deno using Chocolatey for Windows. For Installing Deno using Chocolatey, run the following command:  

choco install deno


This will install Deno on the local System to the default $HOME/.deno directory. This is the default Deno’s Base directory and is referenced via the environmental variable DENO_DIR. 
 

Installing Deno using Chocolatey


Getting Started: To check DenoJS Installation, run the command: 

deno --version


This should provide you with the version of TypeScript, V8 Engine and Deno. 

deno --version


If we simply execute the command: 

deno


It runs the command: 

deno repl

Which opens up the REPL interface that stands for READ EVAL PRINT LOOP which means that we can type in basic JavaScript code from within the Command-line and it will compile, executes and prints the result. 

We will execute a simple Deno Script in our local, located at the standard deno.land/std/ URL. We can directly run this Script from the remote URL by using the Command:  

deno run https://deno.land/std/examples/welcome.ts
welcome.ts

This is the link to the welcome.ts script in the official Deno docs Examples. We can view the Source code by simply navigating to that URL. The deno run command compiles the Script and executes the Script to display the result in your console. Deno Automatically knows whether we are running this script via the URL or just viewing it in the Browser.

To install the script on the local machine, we can run the command: 

deno install https://deno.land/std/examples/welcome.ts


This will install the welcome.ts script to the $Home/.deno/bin directory. The file will be downloaded as a .cmd file on Windows. In case the Installation already Exists, we need to explicitly overwrite it. 

deno install


 

Output


Note: Run CMD with Administrator Privileges to avoid unnecessary errors with Deno.
We will create a welcome.ts file on the local machine and execute it with Deno. 
welcome.ts 

Javascript

console.log("Welcome to GeeksForGeeks");
                      
                       

To execute this file, Run the command: 

deno run welcome.ts

Output:  

Output


 



Next Article
NodeJS Introduction
author
radheshkhanna
Improve
Article Tags :
  • JavaScript
  • Node.js
  • Web Technologies
  • JavaScript-Misc

Similar Reads

  • Ember.js Introduction
    Ember.js is an open-source JavaScript framework used for developing large client-side web applications which is based on Model-View-Controller (MVC) architecture. Ember is designed for reducing development time and increasing productivity, it is one of the fastest-growing front-end application frame
    3 min read
  • Dojo Introduction
    Dojo is an open-source library that is used for the development of fast, robust, and scalable web pages. It works on javascript. It is the same as another javascript toolkit that is used for designing web pages and cross -platforms applications. The main feature of this toolkit is that Dojo has a co
    3 min read
  • p5.js Introduction
    p5.js is a JavaScript library used for creative coding. It is based on Processing which is a creative coding environment. The main focus of processing is to make it easy as possible for beginners to learn how to program interactive, graphical applications, to make a programming language more user-fr
    2 min read
  • NodeJS Introduction
    NodeJS is a runtime environment for executing JavaScript outside the browser, built on the V8 JavaScript engine. It enables server-side development, supports asynchronous, event-driven programming, and efficiently handles scalable network applications. NodeJS is single-threaded, utilizing an event l
    5 min read
  • Introduction to ES6
    ES6 or ECMAScript 2015 is the 6th version of the ECMAScript programming language. ECMAScript is the standardization of Javascript which was released in 2015 and subsequently renamed as ECMAScript 2015. New Features in ES61. The let KeywordThe let variables are mutable i.e. their values can be change
    4 min read
  • Next.js Introduction
    Next.js is a powerful and flexible React framework that has quickly become popular among developers for building server-side rendered and static web applications. Created by Vercel, Next.js simplifies the process of developing modern web applications with its robust feature set. In this article, we’
    5 min read
  • Introduction to Javascript Engines
    JavaScript is a scripting language and is not directly understood by computer but the browsers have inbuilt JavaScript engine which help them to understand and interpret JavaScript codes. These engines help to convert our JavaScript program into computer-understandable language.  A JavaScript engine
    4 min read
  • Introduction to JavaScript
    JavaScript is a versatile, dynamically typed programming language used for interactive web applications, supporting both client-side and server-side development, and integrating seamlessly with HTML, CSS, and a rich standard library. JavaScript is a single-threaded language that executes one task at
    8 min read
  • Svelte | Introduction and Installation
    Svelte is the new methodology for creating web apps. It can be used in a small part of a code or in an entire single page application. It is a compiler not a framework, which is faster than other JavaScript libraries like ReactJS, AngularJS, VueJS. It is used to create reactive web apps. If any chan
    2 min read
  • Mithril.js Introduction and Environment Setup
    Mithril is a client-side JavaScript framework used to create a single-page application. There are lots of other popular frameworks, and those are popular enough and huge community support for them like React, Vue, and Angular. Then why should you choose Mithril over those fantastic performers framew
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences